Code to auto fill Column A and B from Cells A2 and B2 down to last row.

Bill Williamson

Board Regular
Joined
Oct 7, 2019
Messages
124
Hello Everyone,

I am pulling a Customer Name and a CSO number from a workbook Name.
Populating them into Column A2 and B2
This part is working fine., What I need to do is have them fill down to last used row when the row qty varies between worksheets.


I am a newbie at this VBA so any advice you could give would be helpful.
This is the part of the macro I need help with.

[Code}
Dim CSO As String
Dim Customer As String
Dim lngstart As Long
Dim lngEnd As Long
Dim LeftEnd As Long
Dim RhtEnd As Long

'Find CSO# Starting and end Positions
' Which will be between the " " and the "."
'Pull CSO# out of file name

lngstart = InStr(ActiveWorkbook.Name, " ")
lngEnd = InStr(ActiveWorkbook.Name, ".")
CSO = Mid(ActiveWorkbook.Name, lngstart + 1, lngEnd - lngstart - 1)

'Pulls Customer Name out of File Name

LeftEnd = InStr(ActiveWorkbook.Name, "Left")
RhtEnd = InStr(ActiveWorkbook.Name, " ")
Customer = Mid(ActiveWorkbook.Name, Leftstart + 1, RhtEnd - Leftstart - 1)

'Populates A2 and B2 with Data

ActiveSheet.Range("A2") = CSO
ActiveSheet.Range("A1") = "CSO#"
ActiveSheet.Range("B1") = "Customer"
ActiveSheet.Range("B2") = Customer

[Code/]

Thanks in advance for any ideas.


Bill Williamson
 
Because Leftstart was never given a value so it's treated as 0, so Customer = Mid(ActiveWorkbook.Name, Leftstart + 1, RhtEnd - Leftstart - 1) becomes
Customer = Mid(ActiveWorkbook.Name, 1, RhtEnd - 1) which is correct given the structure of your file names.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
OK I get it, I was not too far off, thank you both for the help. Its is running great.

Now I am going to work on transferring it to another workbook.
If I cant get it figured out I will be back for a new thread

Thanks again both of you.

Regards,

Bill Williamson
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top