dabug80
asked on
Excel: Simple macro coding fix
Hi,
Below is my macro. I get an error on line 14.
I am trying to select the first blank cell in column A - so I can populate it with "Open". What am I doing wrong?
Thanks.
Below is my macro. I get an error on line 14.
I am trying to select the first blank cell in column A - so I can populate it with "Open". What am I doing wrong?
Sub mac_1pasteallocation()
Dim firstEmptyRow As Long
Dim firstEmptyStatus As Long
firstEmptyRow = Sheets("Data").Range("B" & Rows.Count).End(xlUp).Row + 1
Sheets("Master").Range("B3:B12").Copy
Sheets("Data").Range("B" & firstEmptyRow).PasteSpecial Paste:=xlPasteAll, Transpose:=True
Application.CutCopyMode = False
'This sets the status to open
firstEmptyStatis = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets("Data").Range("A" & firstEmptyStatus).Select
ActiveCell.FormulaR1C1 = "Open"
End Sub
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The first empty cell in column A is a dropdown box. I would like the first option (open). To be selected.
So do I have to add the following:
ActiveCell.FormulaR1C1 = "Open"
Instead of .value = "Open"
So do I have to add the following:
ActiveCell.FormulaR1C1 = "Open"
Instead of .value = "Open"
Do you mean a Data validation list? If so then .Value works as well. You can still use FormulaR1C1 but the main thing is that you do not need to Select the Sheet or the Cell
ASKER
Yes. A data validation list.
Attached is my sample spreadsheet. To activate the macro and see the error - click the 'Add lead button'.
eeTemplate-Integrated-Webleadsv8.xlsm
Cheers
Attached is my sample spreadsheet. To activate the macro and see the error - click the 'Add lead button'.
eeTemplate-Integrated-Webleadsv8.xlsm
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I've found the cause, you have a typo
Should be
And so
If you use Option Explicit as I have you will be warned of such errors, see this
firstEmptyStatis = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1
Should be
firstEmptyStatus = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1
And so
Option Explicit
Sub mac_1pasteallocation()
Dim firstEmptyRow As Long
Dim firstEmptyStatus As Long
firstEmptyRow = Sheets("Data").Range("B" & Rows.Count).End(xlUp).Row + 1
Sheets("Master").Range("B3:B12").Copy
Sheets("Data").Range("B" & firstEmptyRow).PasteSpecial Paste:=xlPasteAll, Transpose:=True
Application.CutCopyMode = False
'This sets the status to open
firstEmptyStatiu = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets("Data").Range("A" & firstEmptyStatus).Value = "Open"
End Sub
If you use Option Explicit as I have you will be warned of such errors, see this
ASKER
Thanks.
I see the mispelling. Also, I removed the +1 row reference for firstemptystatus due to the '0' pasting.
Cheers.
I see the mispelling. Also, I removed the +1 row reference for firstemptystatus due to the '0' pasting.
Cheers.
Glad your issue has been resolved. :)
Open in new window