简体   繁体   中英

VBA How to extend range of macro to entire sheet

How can I pass every value from combo box through a sheet and retrieve a single cell that will be stored on a separate sheet?

Sheet 1: Enter a Location from Combo Box (Stored on Sheet 2) and date to retrieve hourly temperature from external database for 90 days starting from date that was inputted. Stores maximum value. Sheet 3: Need to go through each location and store max value next to Location name,

Right now, My macro for one iteration is:

  ActiveWindow.SmallScroll Down:=-6
    Range("B1").Select
    Selection.NumberFormat = "General"
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "='Load Book'!R[2]C[-1]"
    Range("B2").Select
    Sheets("Max Amps").Select
    ActiveSheet.Calculate
    Sheets("Load Book").Select
Range("B3").Select
Selection.NumberFormat = "0"
ActiveSheet.Calculate

This is only working for whatever is in that one cell. And if I try to record a macro for the next iteration too, the first maximum temperature changes to be whatever is in the second location too. How can I get the max temperature store, then move to next location without first being affected? And how can I apply this to 400 locations?

First change the code

     ActiveWindow.SmallScroll Down:=-6
    Range("B1").NumberFormat = "General"
    Range("B1").FormulaR1C1 = "='Load Book'!R[2]C[-1]"
    Sheets("Max Amps").Select
    ActiveSheet.Calculate
    Sheets("Load Book").Select
Range("B3").NumberFormat = "0"
ActiveSheet.Calculate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM