| View previous topic :: View next topic |
| Author |
Message |
Valhalla Newbie

Joined: 05 Jul 2012 Posts: 3
|
Posted: Thu Jul 05, 2012 1:37 am Post subject: [Solved} IF macro help |
|
|
Hey everyone!
Im just getting into macros but i am trying to make/get one for a spreadsheet that i am making. The basic purpose would be that of an if function. For instance, with the following numbers represented in A1 and B1 respectively
32 7
i want the macro to say if number in B1 is >6 then subtract 4 from A1 and give the solution back into the A1 cell. I have made a button to assign the macro to so that each time i push it the macro runs. I have several instances that i need to run so just a starting point would help, as i have all but torn out my hair trying to figure something out.
Thanks,
Val
Last edited by Valhalla on Thu Jul 05, 2012 3:07 pm; edited 2 times in total |
|
| Back to top |
|
 |
patel Power User

Joined: 14 Apr 2012 Posts: 54 Location: Italy
|
Posted: Thu Jul 05, 2012 5:47 am Post subject: |
|
|
Hi
| Code: | Sub Main
Dim Doc As Object, Sheet As Object, CellRange As Object
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Sheet = Doc.Sheets.getByIndex(index)
oSheet = Doc.getSheets().getByIndex(0)
CellB1 = Sheet.getCellRangeByName("B1")
CellA1 = Sheet.getCellRangeByName("A1")
if CellB1.value > 6 then
CellA1.value = CellA1.value -4
end if
End Sub |
remenber, the title of the topic is very important, must reflect the subject matter, please change it _________________ If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button). |
|
| Back to top |
|
 |
Valhalla Newbie

Joined: 05 Jul 2012 Posts: 3
|
Posted: Thu Jul 05, 2012 3:06 pm Post subject: |
|
|
| this worked really well hopefully ill be able to play with it and get all the numbers i want i really appreciate it! |
|
| Back to top |
|
 |
|