Dynamic Ranges with VBA

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ต.ค. 2024

ความคิดเห็น • 12

  • @thesmallman
    @thesmallman  4 ปีที่แล้ว +3

    Perfecting dynamic ranges are a fundamental lesson in the VBA language. Practice this technique over and over to get good at it. :)

  • @not1AM
    @not1AM ปีที่แล้ว +1

    Hi. Thanks for this video.. but how can i make the address variable>>> something like:
    let A as variant
    A=C3
    MsgBox [A].Value

    • @thesmallman
      @thesmallman  ปีที่แล้ว

      You were almost there. You have to trap the value when you are working out what A will be equal to.
      Sub test()
      Dim A As Variant
      A = [C3].Value
      MsgBox A
      End Sub
      Give the above a try. Should work.

    • @not1AM
      @not1AM ปีที่แล้ว

      Thanks for the response.. But what I am asking is how to make the address of a cell as variable.
      Not saving the value of a cell to a variable

    • @thesmallman
      @thesmallman  ปีที่แล้ว

      @@not1AM I do not understand what you are asking. How do you know where the cell is unless you declare it?

  • @amritachopra4765
    @amritachopra4765 2 ปีที่แล้ว

    Thank yo so much for the great help. I was able to successfully copy from one workbook to another. But unfortunately it didn't copy the dropdown part. Can you please suggest anything?

  • @Red00022
    @Red00022 ปีที่แล้ว

    This is very nice. Do you happen to know the difference between this and just using range.UsedRange?

    • @thesmallman
      @thesmallman  ปีที่แล้ว

      You can't set a range with the UsedRange method. You have to refere to the activesheet in the following way Activesheet.UsedRange. Which looks like you have recorded the macro. The above is more elegant in my opinion.

  • @vivinski
    @vivinski 2 ปีที่แล้ว +1

    How do you then use the Dynamic Range sub inside another macro so that VBA picks up the full data set when the amount of raw data is variable?

    • @thesmallman
      @thesmallman  ปีที่แล้ว

      You can send a dynamic range between variables as follows
      Sub SendTO()
      Dim lr As Long
      lr = [A1048576].End(xlUp).Row
      Other lr
      End Sub
      Sub Other(TheLR)
      MsgBox TheLR
      End Sub
      This procedure sends the Last Row (LR) from SendTo to the Other procedure. This is how you get a variable to transfer between macros. Hope that helps.

  • @mr.write1433
    @mr.write1433 10 หลายเดือนก่อน

    i only want the middle ? like row 6-10 and i want to be able to change it anytime without changing the codes in vba

    • @thesmallman
      @thesmallman  10 หลายเดือนก่อน

      Depends what your data looks like. If you don't have data in row 7 then the current region method I shared will work. If you have data in row 7 you don't want included that becomes more involved. You could use the FIND in VBA to locate something unique in the bottom of your dataset and trap that row via a find and that way you never have to change your code provided you always have that unique item in the dataset.