Column references in VBA

Ron903

New Member
Joined
Nov 28, 2017
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi all -
New to VBA and this forum. Hoping to find a quick answer to what is probably very basic.

I am writing a macro that will loop through spreadsheets with a varying number of columns and rows. One of my needs is to find the minimum and maximum value in the active column based on an index/counter. In this case, the column reference is ColNum.

Column index/loop -
For ColNum = 1 To TotalCols

Find min and max -
FldMin = Application.WorksheetFunction.Min(rng)
FldMax = Application.WorksheetFunction.Max(rng)

What I am struggling with is how to define the range (rng) using ColNum for use in the min and max functions. Have tried several things I have seen online and I'm just not grasping the concept.

Thanks,
Ron
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi & welcome to the board.
Try
Code:
FldMin = Application.WorksheetFunction.Min(Columns(ColNum))
 
Upvote 0
Thank you very much! That worked perfectly. I was making that way harder than I apparently needed to. Guess I have a lot to learn...
 
Upvote 0
Glad to help & thanks for the feedback.
Unfortunately it's very easy to over complicate things and It's something we've all been guilty of at sometime or another.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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