Stuck on a VBA task

Platypus

New Member
Joined
Apr 7, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hey Guys,

I've just begun digging into excel, Macro's and VBA and have taken up a small task I get in work quite often and am trying to automate it.

Hit a sticking point, and wondering if someone could help me.

Excel files I get on a regular basis, vary in size, can be between 12,000 and 20000 rows. each data set has same columns etc. so it is uniform data.

I have set up a macro to pull in the data, add columns, formulas, headers etc - which I intend of including under a master file, and having a pivot with slicers to get what data I need, when I need it.

Issue is, I've got everything up and running - it is giving me the desired results, but when I done up the VBA code (admittedly pieced together from trial and error and online) I hardcoded the end cell for each specific function eg. C1:C17023 - which worked perfectly for the first data set, but obviously needs to be dynamic.

Below is one of many formula's I have put in, in order to auto-populate down the column.

Is there some way, before I actually start pulling in these ranges, that I can get the total rows, and put it into an integer variable - or something along them lines.
----------------------------------------------------------------------------
Range("C2").Formula = "=VLOOKUP(E2,Index!$B$45:$C$49,2,False)"

Range("C2").Select

Selection.AutoFill Destination:=Range("c2:C10686")
---------------------------------------------------------------------------

When I am first pulling in the data, I am selecting a range, which I know ill be in the data set, and basically doing a CTRL+A on it
--------------------------------------------------------------------------
Range("A15).Select
ActiveCell.CurrentRegion.Select
-------------------------------------------------------------------------

Then I am pasting into another sheet to add formula's etc.

Apologies for being so long winded! Help would be appreciated
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi & welcome to MrExcel.
Will column A always have data in every cell for the used range?
 
Upvote 0
In that case you can use something like
VBA Code:
Dim UsdRws As Long
UsdRws = Range("A" & Rows.Count).End(xlUp).Row
Range("C2:C" & UsdRws).Formula = "=VLOOKUP(E2,Index!$B$45:$C$49,2,False)"
 
Upvote 0
In that case you can use something like
VBA Code:
Dim UsdRws As Long
UsdRws = Range("A" & Rows.Count).End(xlUp).Row
Range("C2:C" & UsdRws).Formula = "=VLOOKUP(E2,Index!$B$45:$C$49,2,False)"

Thanks for that!

Although it is giving me an error when setting the variable,

Run-time error '1004' : application-defined or object-defined error.
 

Attachments

  • error.png
    error.png
    26.2 KB · Views: 8
Upvote 0
You have miss-typed it. It should be xlup (lower case L not the number one).
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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