Excel 2000 VBA feeding a value to a formula

billfinn

Board Regular
Joined
Jun 7, 2018
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
Good afternoon!
Currently I pull a huge text file from the AS400 monthly and dump it in my project workbook, then format it. I now need to be able to modify the cost field by in VBA using a multiplier.

Currently the AS400 file comes in with 63,289 rows. I run a macro to delete all page, report and column headers and format the result and end up with 58123 rows. At that point the macro places the multiplier in an empty cell, does a copy/paste special/multiply to get the new cost. That portion of the macro has 58123 hard coded. I’d like to be able to feed the number of used rows after formatting to the copy/paste statement as I am certain more items will be added in the future.
The portion of the macro I'm trying to modify is below, with the problem area in red.

Code:
Worksheets("Item Master").Activate  'make Item Master the active worksheet
Dim Cnt as integer        
Cnt = ActiveSheet.UsedRange.Rows.Count
        Range("F1") = 1.32   'set multiplier to increase item cost to builder cost
        Range("F1").Copy    'copy multiplier
       [COLOR=#ff0000][B] Range("C1:C&Cnt")[/B][/COLOR].PasteSpecial xlPasteAll, Operation:=xlMultiply   'paste special/multiply for new cost  
        ActiveSheet.UsedRange 'Shrink used area down to size of formatted Item Master

I thought perhaps I could define the variable Cnt and pass it to the formula but I either used incorrect syntax or am on the wrong path.
Any suggestions, hints or input are gratefully accepted.
Thanks,
Bill
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try
Code:
Worksheets("Item Master").Activate  'make Item Master the active worksheet
Dim Cnt As [COLOR=#ff0000]Long[/COLOR]
Cnt = ActiveSheet.UsedRange.Rows.Count
        Range("F1") = 1.32   'set multiplier to increase item cost to builder cost
        Range("F1").Copy    'copy multiplier
        Range("C1:C[COLOR=#ff0000]" & Cnt[/COLOR]).PasteSpecial xlPasteAll, Operation:=xlMultiply 'paste special/multiply for new cost
        ActiveSheet.UsedRange 'Shrink used area down to size of formatted Item Master
 
Upvote 0
Fluff,
Once again you have solved my problem!! I appreciate it very much! Looks like I was close. I'll have to look up the difference between Integer and Long. The definition of Integer led me to believe that would work but obviously it didn't!
thanks very much - on to the next task.
Bill
 
Upvote 0
With the change to the Range you would still have had a problem using integer as that has a maximum value of 32,767, whereas long has a max of 2,147,486,647
 
Upvote 0
Yeah, just figured that out. Apparently I was looking at Variable limits for something other than VBA. Must be Christmas Fever...
Thanks again Fluff.
Bill
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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