Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Shift cells to the left

Hi all. Below I have the following formulas in cells B3-F3. What I am trying
to do, is any data that I have in cell B4-F9, I would like that data to shift
to the left when the date changes in cell B3-F3.

B C D E F
3 =NOW() =NOW()+1 =NOW()+2 =NOW()+3 =NOW()+4
4
5
6
7
8
9

Thanks in advance for any help you might have.
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Shift cells to the left

This will work, but you need to be aware of
the quirks.
1. For Cells(1, 11) reference, you will
need to pick a cell on your worksheet, that you
know will not be used for anything else and
is not on the rows that will shift, to
substitute that cell reference

2. The data that goes into that cell is set
each time the macro runs, but will not change
until the date changes. The date changes by
your computer date change with the NOW() function.

3. When the cells shift left, the extreme right
column for the shifted rows that previously had
data becomes blank, leaving only the date header.

If you can live with those things then copy this
to your worksheet code module for the sheet you
want to change.

Private Sub Worksheet_Activate()
If Worksheets(1).Cells(3, 2) < Worksheets(1).Cells(1, 11) Then
Worksheets(1).Range("B4:B9").Delete xlShiftToLeft
End If
x = Format(Cells(1, 1).Value, "m/d/yy")
Worksheets(1).Range("K1") = x
End Sub



"Steve D." wrote:

Hi all. Below I have the following formulas in cells B3-F3. What I am trying
to do, is any data that I have in cell B4-F9, I would like that data to shift
to the left when the date changes in cell B3-F3.

B C D E F
3 =NOW() =NOW()+1 =NOW()+2 =NOW()+3 =NOW()+4
4
5
6
7
8
9

Thanks in advance for any help you might have.
Steve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Shift cells to the left

Corrects the value for x to "B3" date ref:

Private Sub Worksheet_Activate()
If Worksheets(1).Cells(3, 2) < Worksheets(1).Cells(1, 11) Then
Worksheets(1).Range("B4:B9").Delete xlShiftToLeft
End If
x = Format(Cells(3, 2).Value, "m/d/yy")
Worksheets(1).Range("K1") = x
End Sub


"Steve D." wrote:

Hi all. Below I have the following formulas in cells B3-F3. What I am trying
to do, is any data that I have in cell B4-F9, I would like that data to shift
to the left when the date changes in cell B3-F3.

B C D E F
3 =NOW() =NOW()+1 =NOW()+2 =NOW()+3 =NOW()+4
4
5
6
7
8
9

Thanks in advance for any help you might have.
Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Shift cells to the left

Steve, sorry to keep changing this on you but you
do want something that works right, so this will do
the trick if you change the =Now() in "B3" to =TODAY().
The date in the trigger cell kept mismatching due to the
time reference. This tested OK and will only shift the cells
on the first activation on the same day.

Private Sub Worksheet_Activate() 'Shift range of cells on date change
If Worksheets(1).Cells(3, 2) < Worksheets(1).Cells(1, 11) Then
Worksheets(1).Range("B4:B9").Delete xlShiftToLeft
End If
x = Worksheets(1).Cells(3, 2).Value
Worksheets(1).Range("K1") = Format(x, "m/d/yy")
End Sub

If for some reason, it does continue to shift on each iteration
of the code on the same day, then the date mismatch is the
problem and you can play with the formatting until it works or
somebody gives you a better code set.

"Steve D." wrote:

Hi all. Below I have the following formulas in cells B3-F3. What I am trying
to do, is any data that I have in cell B4-F9, I would like that data to shift
to the left when the date changes in cell B3-F3.

B C D E F
3 =NOW() =NOW()+1 =NOW()+2 =NOW()+3 =NOW()+4
4
5
6
7
8
9

Thanks in advance for any help you might have.
Steve

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Shift cells to the left

JLGWhiz,
Thanks for the quick response and answer to my question, works great.
Steve

"JLGWhiz" wrote:

Steve, sorry to keep changing this on you but you
do want something that works right, so this will do
the trick if you change the =Now() in "B3" to =TODAY().
The date in the trigger cell kept mismatching due to the
time reference. This tested OK and will only shift the cells
on the first activation on the same day.

Private Sub Worksheet_Activate() 'Shift range of cells on date change
If Worksheets(1).Cells(3, 2) < Worksheets(1).Cells(1, 11) Then
Worksheets(1).Range("B4:B9").Delete xlShiftToLeft
End If
x = Worksheets(1).Cells(3, 2).Value
Worksheets(1).Range("K1") = Format(x, "m/d/yy")
End Sub

If for some reason, it does continue to shift on each iteration
of the code on the same day, then the date mismatch is the
problem and you can play with the formatting until it works or
somebody gives you a better code set.

"Steve D." wrote:

Hi all. Below I have the following formulas in cells B3-F3. What I am trying
to do, is any data that I have in cell B4-F9, I would like that data to shift
to the left when the date changes in cell B3-F3.

B C D E F
3 =NOW() =NOW()+1 =NOW()+2 =NOW()+3 =NOW()+4
4
5
6
7
8
9

Thanks in advance for any help you might have.
Steve



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-ID and Delete/left shift cells when a cell contains text? IndyToothDoc Excel Discussion (Misc queries) 0 June 29th 09 06:06 PM
How can I shift my data line to the left? bmeril Charts and Charting in Excel 1 January 19th 06 07:59 PM
Move/Shift cells left or right in a row T.Taylor Excel Programming 0 November 14th 05 03:15 PM
Shift data to left Steph[_3_] Excel Programming 4 April 13th 05 03:58 AM
VBA - Left Shift to be Activated when Sheet is selected. BradWarr Excel Programming 1 June 22nd 04 01:25 PM


All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"