Modifying VBA Code to Include All Used Rows (Dynamic, Not Static)

Justinian

Well-known Member
Joined
Aug 9, 2009
Messages
1,557
Office Version
  1. 365
Platform
  1. Windows
I import daily data into Excel for a morning report and the data does not always take up the same amount of rows. One day, it could go down to row 79 but the next day, it could go down to row 90. How can I modify the VBA below so that the code looks at all used rows instead of this static range?

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Selection.FormulaR1C1 = "=RIGHT(RC[-6],LEN(RC[-6])-FIND(""-"",RC[-6],1))"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G79")
Range("G2:G79").Select
Selection.Copy[/FONT]
 

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
How about
Code:
   Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=RIGHT(RC[-6],LEN(RC[-6])-FIND(""-"",RC[-6],1))"
 
Upvote 0
That did not do anything. I just need to modify this portion:

Selection.AutoFill Destination:=Range("G2:G90")
Range("G2:G90").Select
 
Last edited:
Upvote 0
Assuming that you are putting the formula in G2, then my code replaces all of yours and will fill the formula down to the last row of col A.
 
Upvote 0
This part
Code:
[FONT=Verdana]Selection.FormulaR1C1 = "=RIGHT(RC[-6],LEN(RC[-6])-FIND(""-"",RC[-6],1))"
    Range("G2").Select
    Selection.AutoFill Destination:=Range("G2:G79")[/FONT]
 
Upvote 0
It is not working. How about I post my worksheet so you can see it? I should have done that earlier.

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]https://app.box.com/s/8eke1c83ca7kihaxqoflp3zlwepy0mm3

[/FONT]
 
Upvote 0
The reason it doesn't work is that col A does not contain any values with a - in them, therefore the formula returns #VALUE!
 
Last edited:
Upvote 0
When I do put items that contain a "-" look what happens below row 79:

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]https://app.box.com/s/ufphfie4vs55ct936ts1up5ildim1mlj[/FONT]
 
Upvote 0
The formula in col G returns


Book1
ABCDEFG
793502K037 Tower 2Bd Premium *******09/05/201911/13/2019Completed: 09/30/19 Scheduled: 09/09/19 remove radiators# 924583-1 and A/C REMOVAL #924600-1#VALUE!
8042-4207L036 Tower 2Bd Premium09/14/201911/13/2019In progress: Scheduled: 09/17/19 SM TO4207L
8133-3300J036 Tower 2Bd Premium10/01/201911/26/2019In progress: Scheduled: 10/02/19 REMOVE RADIATORS #928063-13300J
8246-4608B036 Tower 2Bd Premium09/29/201911/27/2019In progress: REMOVE RADIATORS #927751-14608B
8346-4608B09/29/201911/27/2019In progress: REMOVE RADIATORS #927751-14608B
Make Ready Board
Cell Formulas
RangeFormula
G79=RIGHT(A79,LEN(A79)-FIND("-",A79,1))


Which is correct.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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