Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Run a macro from an If statement

I am trying to automate a spreadsheet that is used with a datalogger.
Within the spreadsheet I have four cells that are linked to the
datalogger system and changes that values at the end of the test
cycle. If the values change I compare them to the last known data
values with an if statement (cell k4). From that point I update the
counter and move the data from row 3 to row 4, than move the data set
down to the table below.

The marco I wrote works find but I want to automate it so it runs
either in a loop or when the value of K4 changes. (Remembering K4 is
an if statement). Again I want to eliminate the need for the user to
activate my macro but instead just start it once and it will run till
the spreadsheet if full.

I am a new to coding so any help would be appreciated.

Sub CheckChange()
'
' CHECK FOR CHANGE BETWEEN ROW 3 & 4 (OCCURS WHEN DATA LOGGER IS
UPDATED)
' IF CELL K4 IS CHANGE, MOVE ROW 3 TO 4, INCREASE THE COUNTER
'
If Range("K4") = "Change" Then
Range("B3:J3").Select
Application.CutCopyMode = False
Selection.Copy
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
If Range("E3") = "1" Then
Range("E3").Select
ActiveCell.FormulaR1C1 = "2"
ElseIf Range("E3") 1 Then
Range("E3").Select
ActiveCell.FormulaR1C1 = "=R[+1]C+1"
Range("E3").Select
End If
'
' SINCE K4 DOES EQUAL "CHANGE" THAN INSERT A ROW AT 14 AND COPY
' ROW 4 TO 14. THIS WILL PLACE THE LAST DATA COLLECTION AT THE TOP OF
THE SHEET.
'
Rows("14:14").Select
Selection.Insert Shift:=xlDown
Rows("4:4").Select
Selection.Copy
Rows("14:14").Select
ActiveSheet.Paste
Range("K14").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("B4").Select
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run a macro from an If statement

Probably use the calculate event to call your sub

http://www.cpearson.com/excel/events.htm for an overview.

--
Regards,
Tom Ogilvy


"Steve" wrote:

I am trying to automate a spreadsheet that is used with a datalogger.
Within the spreadsheet I have four cells that are linked to the
datalogger system and changes that values at the end of the test
cycle. If the values change I compare them to the last known data
values with an if statement (cell k4). From that point I update the
counter and move the data from row 3 to row 4, than move the data set
down to the table below.

The marco I wrote works find but I want to automate it so it runs
either in a loop or when the value of K4 changes. (Remembering K4 is
an if statement). Again I want to eliminate the need for the user to
activate my macro but instead just start it once and it will run till
the spreadsheet if full.

I am a new to coding so any help would be appreciated.

Sub CheckChange()
'
' CHECK FOR CHANGE BETWEEN ROW 3 & 4 (OCCURS WHEN DATA LOGGER IS
UPDATED)
' IF CELL K4 IS CHANGE, MOVE ROW 3 TO 4, INCREASE THE COUNTER
'
If Range("K4") = "Change" Then
Range("B3:J3").Select
Application.CutCopyMode = False
Selection.Copy
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
If Range("E3") = "1" Then
Range("E3").Select
ActiveCell.FormulaR1C1 = "2"
ElseIf Range("E3") 1 Then
Range("E3").Select
ActiveCell.FormulaR1C1 = "=R[+1]C+1"
Range("E3").Select
End If
'
' SINCE K4 DOES EQUAL "CHANGE" THAN INSERT A ROW AT 14 AND COPY
' ROW 4 TO 14. THIS WILL PLACE THE LAST DATA COLLECTION AT THE TOP OF
THE SHEET.
'
Rows("14:14").Select
Selection.Insert Shift:=xlDown
Rows("4:4").Select
Selection.Copy
Rows("14:14").Select
ActiveSheet.Paste
Range("K14").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("B4").Select
End If

End Sub


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
Macro to If Statement JHusker Excel Discussion (Misc queries) 7 October 10th 08 10:39 PM
Macro statement when opening file, but no macro Robert Smith[_3_] Excel Programming 3 May 20th 07 05:58 PM
HELP w/ Macro and IF Statement randy_tn Excel Programming 1 November 3rd 04 01:49 AM
use of Macro in If statement Tom Ogilvy Excel Programming 0 July 22nd 04 05:27 PM
Macro statement Sheela Excel Programming 1 September 2nd 03 10:17 AM


All times are GMT +1. The time now is 06:32 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"