How do I drag excel Table data to right dynamically using vba code

vrsharma

New Member
Joined
Aug 4, 2019
Messages
18
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello Expertise,

I want to write VBA code for dragging excel Table range data dynamically to Right side column wise as per given date.
For eg. If I give Date for "Sep-19" in Worksheet it should automatically drag the table range to right containing Sept-19 data. I am Excel 2016 version.
Below is the table data:

Month18-OctNov-18Dec-1819-JanFeb-19Mar-19April-19May-19June-19July-19Aug-19
Cumulative Count1070010810109301105011163112101128011350114401155019929
Devices5705755825925973599604607612617617
Connectors2912952982993027305306308310314314
Terminals2092112132142163217218220222224224
Rest96309729983710268100467100891015210225102961039518774

<tbody>
</tbody>

I have tried some code, below the vba code for it:

Sub Macro4()

Range("Table1[[#Headers],[Month]]").Select
Selection.End(xlToRight).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FillRight
Range("Table1[[#All],[Aug-19]:[Sep-19]]").Select

End Sub

I want the range "Aug-19]:[Sep-19]]" in last of code to be set up dynamic as per given month, how can I do it?

Thank you in advance.
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi vrsharma,

i don't fully understand what you mean with 'drag to right'.
Also you mention: "If I give date for "Sep-19" in Worksheet". Where / how do you enter this date?

Let us assume that you fill in the date "sep-19" in a cell A1.
then what needs to happen?
  1. a column sep-19 needs to be added to the right side of the table. Or:
  2. the date sep-19 needs to be found in the header and the table scrolled to this column. Or:
  3. something else

Let me, and the other readers, know what you mean here.

Please explain clearly. (I don't think you mean 'drag' because you drag with a mouse, not with code. I assume you mean scroll, but please clarify)
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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