Would like help and advice on working with codes and buttons on MS-Excel
up vote
0
down vote
favorite
I am currently working on an Excel document where I would like to click on a cell and have a box pop-up with options of more command buttons to choose from. When the user clicks on one of the buttons within the user form the button it would then move a selection of that line of A:G to another sheet. I will have multiple lines and would like to code to adjust to the box where the initial command was initiated from. I have the first button and the user form complete and it is working well. The issue is on the next set of buttons to copy, paste and delete the line. Here is what I have so far. Any help would be appreciated.
Private Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
With ActiveSheet
For n = nReference To nLastRow Step 1
ActiveSheet.UsedRange
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row + 1
Set Reference = Selection
Next Copy_to_Range()
ActiveWorksheets.Range("Reference").Copy
Destination = Worksheets("Fire Chief").Range("nLastRow")
Worksheets("Fire Chief").Columns("A:G").AutoFit
End Sub
So instead of the code listed above, I tried to rework it with some of the input that was provided. Basically this in a way would work like an Access document, and when the button was clicked it would do all of the work for the end user. I work in a fire dept and would like to make it easier on those who have to use it. There are 10 sheets that I have to work with and once I figure out one I will rewrite to match for the other. The new code is below
Option Explicit
Sub BaseFireMarshal_Click()
End Sub
Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
Dim B As Integer
Dim R As Range
Set R = Sheet5.Range("A2:G999")
If Worksheets("ActiveSheet").Range("A:XFD").Copy_ = True Then
Dim continue As Boolean
continue = True
If continue = True Then
Worksheets("Sheet5").Activate
B = Worksheets("Sheet5").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet5").Cells(B + 1, 1).Select
ActiveSheet.Paste
Worksheets("Fire Chief").Columns("A:G").AutoFit
Worksheets("Sheet5").Deactivate
End If
If Application.CutCopyMode = False Then
ThisWorkbook.Worksheets("ActiveSheet").Cells(1, 1).Select
End If
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
excel vba excel-vba
add a comment |
up vote
0
down vote
favorite
I am currently working on an Excel document where I would like to click on a cell and have a box pop-up with options of more command buttons to choose from. When the user clicks on one of the buttons within the user form the button it would then move a selection of that line of A:G to another sheet. I will have multiple lines and would like to code to adjust to the box where the initial command was initiated from. I have the first button and the user form complete and it is working well. The issue is on the next set of buttons to copy, paste and delete the line. Here is what I have so far. Any help would be appreciated.
Private Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
With ActiveSheet
For n = nReference To nLastRow Step 1
ActiveSheet.UsedRange
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row + 1
Set Reference = Selection
Next Copy_to_Range()
ActiveWorksheets.Range("Reference").Copy
Destination = Worksheets("Fire Chief").Range("nLastRow")
Worksheets("Fire Chief").Columns("A:G").AutoFit
End Sub
So instead of the code listed above, I tried to rework it with some of the input that was provided. Basically this in a way would work like an Access document, and when the button was clicked it would do all of the work for the end user. I work in a fire dept and would like to make it easier on those who have to use it. There are 10 sheets that I have to work with and once I figure out one I will rewrite to match for the other. The new code is below
Option Explicit
Sub BaseFireMarshal_Click()
End Sub
Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
Dim B As Integer
Dim R As Range
Set R = Sheet5.Range("A2:G999")
If Worksheets("ActiveSheet").Range("A:XFD").Copy_ = True Then
Dim continue As Boolean
continue = True
If continue = True Then
Worksheets("Sheet5").Activate
B = Worksheets("Sheet5").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet5").Cells(B + 1, 1).Select
ActiveSheet.Paste
Worksheets("Fire Chief").Columns("A:G").AutoFit
Worksheets("Sheet5").Deactivate
End If
If Application.CutCopyMode = False Then
ThisWorkbook.Worksheets("ActiveSheet").Cells(1, 1).Select
End If
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
excel vba excel-vba
2
I don't complete understand your question but here are a few pointers that might help improve your existing code: Firstly, Always useOption Explicitin your code. Second, you havenLastRowvariable in quotes in your Destination. If you put your variable inquotes, it's then treated as string and you don't get the value of the variable. Third, never useActiveSheet. Qualify your sheet.ActiveSheetis dangerous because you cannot always be sure ifActiveSheetis always the one you expect
– Zac
Nov 9 at 16:23
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am currently working on an Excel document where I would like to click on a cell and have a box pop-up with options of more command buttons to choose from. When the user clicks on one of the buttons within the user form the button it would then move a selection of that line of A:G to another sheet. I will have multiple lines and would like to code to adjust to the box where the initial command was initiated from. I have the first button and the user form complete and it is working well. The issue is on the next set of buttons to copy, paste and delete the line. Here is what I have so far. Any help would be appreciated.
Private Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
With ActiveSheet
For n = nReference To nLastRow Step 1
ActiveSheet.UsedRange
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row + 1
Set Reference = Selection
Next Copy_to_Range()
ActiveWorksheets.Range("Reference").Copy
Destination = Worksheets("Fire Chief").Range("nLastRow")
Worksheets("Fire Chief").Columns("A:G").AutoFit
End Sub
So instead of the code listed above, I tried to rework it with some of the input that was provided. Basically this in a way would work like an Access document, and when the button was clicked it would do all of the work for the end user. I work in a fire dept and would like to make it easier on those who have to use it. There are 10 sheets that I have to work with and once I figure out one I will rewrite to match for the other. The new code is below
Option Explicit
Sub BaseFireMarshal_Click()
End Sub
Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
Dim B As Integer
Dim R As Range
Set R = Sheet5.Range("A2:G999")
If Worksheets("ActiveSheet").Range("A:XFD").Copy_ = True Then
Dim continue As Boolean
continue = True
If continue = True Then
Worksheets("Sheet5").Activate
B = Worksheets("Sheet5").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet5").Cells(B + 1, 1).Select
ActiveSheet.Paste
Worksheets("Fire Chief").Columns("A:G").AutoFit
Worksheets("Sheet5").Deactivate
End If
If Application.CutCopyMode = False Then
ThisWorkbook.Worksheets("ActiveSheet").Cells(1, 1).Select
End If
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
excel vba excel-vba
I am currently working on an Excel document where I would like to click on a cell and have a box pop-up with options of more command buttons to choose from. When the user clicks on one of the buttons within the user form the button it would then move a selection of that line of A:G to another sheet. I will have multiple lines and would like to code to adjust to the box where the initial command was initiated from. I have the first button and the user form complete and it is working well. The issue is on the next set of buttons to copy, paste and delete the line. Here is what I have so far. Any help would be appreciated.
Private Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
With ActiveSheet
For n = nReference To nLastRow Step 1
ActiveSheet.UsedRange
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row + 1
Set Reference = Selection
Next Copy_to_Range()
ActiveWorksheets.Range("Reference").Copy
Destination = Worksheets("Fire Chief").Range("nLastRow")
Worksheets("Fire Chief").Columns("A:G").AutoFit
End Sub
So instead of the code listed above, I tried to rework it with some of the input that was provided. Basically this in a way would work like an Access document, and when the button was clicked it would do all of the work for the end user. I work in a fire dept and would like to make it easier on those who have to use it. There are 10 sheets that I have to work with and once I figure out one I will rewrite to match for the other. The new code is below
Option Explicit
Sub BaseFireMarshal_Click()
End Sub
Sub FireChief_Click()
Dim i As Long: i = 1
Dim n As Long
Dim nLastRow As Long
Dim lastRow As Integer
Dim B As Integer
Dim R As Range
Set R = Sheet5.Range("A2:G999")
If Worksheets("ActiveSheet").Range("A:XFD").Copy_ = True Then
Dim continue As Boolean
continue = True
If continue = True Then
Worksheets("Sheet5").Activate
B = Worksheets("Sheet5").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet5").Cells(B + 1, 1).Select
ActiveSheet.Paste
Worksheets("Fire Chief").Columns("A:G").AutoFit
Worksheets("Sheet5").Deactivate
End If
If Application.CutCopyMode = False Then
ThisWorkbook.Worksheets("ActiveSheet").Cells(1, 1).Select
End If
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
excel vba excel-vba
excel vba excel-vba
edited Nov 13 at 13:49
asked Nov 9 at 16:13
edisonffa
12
12
2
I don't complete understand your question but here are a few pointers that might help improve your existing code: Firstly, Always useOption Explicitin your code. Second, you havenLastRowvariable in quotes in your Destination. If you put your variable inquotes, it's then treated as string and you don't get the value of the variable. Third, never useActiveSheet. Qualify your sheet.ActiveSheetis dangerous because you cannot always be sure ifActiveSheetis always the one you expect
– Zac
Nov 9 at 16:23
add a comment |
2
I don't complete understand your question but here are a few pointers that might help improve your existing code: Firstly, Always useOption Explicitin your code. Second, you havenLastRowvariable in quotes in your Destination. If you put your variable inquotes, it's then treated as string and you don't get the value of the variable. Third, never useActiveSheet. Qualify your sheet.ActiveSheetis dangerous because you cannot always be sure ifActiveSheetis always the one you expect
– Zac
Nov 9 at 16:23
2
2
I don't complete understand your question but here are a few pointers that might help improve your existing code: Firstly, Always use
Option Explicit in your code. Second, you have nLastRow variable in quotes in your Destination. If you put your variable in quotes, it's then treated as string and you don't get the value of the variable. Third, never use ActiveSheet. Qualify your sheet. ActiveSheet is dangerous because you cannot always be sure if ActiveSheet is always the one you expect– Zac
Nov 9 at 16:23
I don't complete understand your question but here are a few pointers that might help improve your existing code: Firstly, Always use
Option Explicit in your code. Second, you have nLastRow variable in quotes in your Destination. If you put your variable in quotes, it's then treated as string and you don't get the value of the variable. Third, never use ActiveSheet. Qualify your sheet. ActiveSheet is dangerous because you cannot always be sure if ActiveSheet is always the one you expect– Zac
Nov 9 at 16:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I would like to click on a cell and have a box pop-up with options of more command buttons to choose from.
you could do this with grouping columns, from the "data" tab. essentially it collapses/expands a portion of the worksheet.
the button it would then move a selection of that line of A:G to another sheet
cut and paste
would like to code to adjust to the box where the initial command was initiated from
gonna wanna use "selection.column" or "selection.row" in your VBA code for this.
Here is what I have so far.
as for your code, I never use named ranges. I always use range(cells(row,column),cells(row,column)) because then its dynamic.
Try doing that and get back to us.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I would like to click on a cell and have a box pop-up with options of more command buttons to choose from.
you could do this with grouping columns, from the "data" tab. essentially it collapses/expands a portion of the worksheet.
the button it would then move a selection of that line of A:G to another sheet
cut and paste
would like to code to adjust to the box where the initial command was initiated from
gonna wanna use "selection.column" or "selection.row" in your VBA code for this.
Here is what I have so far.
as for your code, I never use named ranges. I always use range(cells(row,column),cells(row,column)) because then its dynamic.
Try doing that and get back to us.
add a comment |
up vote
0
down vote
I would like to click on a cell and have a box pop-up with options of more command buttons to choose from.
you could do this with grouping columns, from the "data" tab. essentially it collapses/expands a portion of the worksheet.
the button it would then move a selection of that line of A:G to another sheet
cut and paste
would like to code to adjust to the box where the initial command was initiated from
gonna wanna use "selection.column" or "selection.row" in your VBA code for this.
Here is what I have so far.
as for your code, I never use named ranges. I always use range(cells(row,column),cells(row,column)) because then its dynamic.
Try doing that and get back to us.
add a comment |
up vote
0
down vote
up vote
0
down vote
I would like to click on a cell and have a box pop-up with options of more command buttons to choose from.
you could do this with grouping columns, from the "data" tab. essentially it collapses/expands a portion of the worksheet.
the button it would then move a selection of that line of A:G to another sheet
cut and paste
would like to code to adjust to the box where the initial command was initiated from
gonna wanna use "selection.column" or "selection.row" in your VBA code for this.
Here is what I have so far.
as for your code, I never use named ranges. I always use range(cells(row,column),cells(row,column)) because then its dynamic.
Try doing that and get back to us.
I would like to click on a cell and have a box pop-up with options of more command buttons to choose from.
you could do this with grouping columns, from the "data" tab. essentially it collapses/expands a portion of the worksheet.
the button it would then move a selection of that line of A:G to another sheet
cut and paste
would like to code to adjust to the box where the initial command was initiated from
gonna wanna use "selection.column" or "selection.row" in your VBA code for this.
Here is what I have so far.
as for your code, I never use named ranges. I always use range(cells(row,column),cells(row,column)) because then its dynamic.
Try doing that and get back to us.
answered Nov 9 at 16:53
Kurt VonOhlen
387
387
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229420%2fwould-like-help-and-advice-on-working-with-codes-and-buttons-on-ms-excel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I don't complete understand your question but here are a few pointers that might help improve your existing code: Firstly, Always use
Option Explicitin your code. Second, you havenLastRowvariable in quotes in your Destination. If you put your variable inquotes, it's then treated as string and you don't get the value of the variable. Third, never useActiveSheet. Qualify your sheet.ActiveSheetis dangerous because you cannot always be sure ifActiveSheetis always the one you expect– Zac
Nov 9 at 16:23