Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro VBA, Drop down IF statement


Code
-------------------

Sub DropDown1_Change()
'
' DropDown1_Change Macro
' Macro recorded 02/11/2005 by 96bst01
If C4 = "1" Then
Range("E4").Select
Selection.NumberFormat = "0%"
ElseIf C4 = "2" Then
Range("E4").Select
Selection.NumberFormat = "£#,##0.00"
End If

End Sub

-------------------


I've got a spreadsheet, it has an ID, either 1 or 2, in cell C4. Thi
is changes when I change my dropdown (These are linked up to anothe
table, with ID 1 and 2).

I'm trying to say, if the value in C4 is 1, format E4 to a percentage
Else if the value in C4 is 2, I want it to format as currency.

As I am a programmer myself, mainly PHP, nothing like this,
understand the structure and know how to debug things. I think th
problem is coming from it not understanding what C4 is. Do I need t
define it?

Thanks

--
Matt_2
-----------------------------------------------------------------------
Matt_2K's Profile: http://www.excelforum.com/member.php...nfo&userid=617
View this thread: http://www.excelforum.com/showthread.php?threadid=48102

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro VBA, Drop down IF statement


Sub change_test ()

if range("C4").value = "1" then
range("E4").numberformat = "0.00%"
if range("C4").value = "2" then
range("E4").numberformat = "$0.00"
end if
end if

end sub

that should work..

--
dok11
-----------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058
View this thread: http://www.excelforum.com/showthread.php?threadid=48102

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro VBA, Drop down IF statement


Thanks. I modified my code a bit using this:


Code
-------------------

Sub DropDown1_Change()
'
' DropDown1_Change Macro
' Macro recorded 02/11/2005 by 96bst01
If Range("C4").Value = "1" Then
Range("E4").Select
Selection.NumberFormat = "0%"
ElseIf Range("C4").Value = "2" Then
Range("E4").Select
Selection.NumberFormat = "£#,##0.00"
End If

End Sub

-------------------


Now, this code works fine for one row, but can I have this on multipl
rows?

E.g. having a drop down box which is linked to a cell reference, BUT
need the C4 and E4 to change depending on the row and cell link. Ho
can I achieve this in VBA

--
Matt_2
-----------------------------------------------------------------------
Matt_2K's Profile: http://www.excelforum.com/member.php...nfo&userid=617
View this thread: http://www.excelforum.com/showthread.php?threadid=48102

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro VBA, Drop down IF statement


You would need to loop the command. This will loop through the comman
until there is no longer a value in column C.

Sub test()
Dim i As Integer

i = 1

Do While Cells(i, 3).Value "0"

If cells(i, 3).Value = "1" Then
cells(i, 5).Select
Selection.NumberFormat = "0%"
ElseIf cells(i, 3).Value = "2" Then
cells(i, 5).Select
Selection.NumberFormat = "£#,##0.00"
End If

i = i + 1

Loop
End Sub

Matt_2K Wrote:
Thanks. I modified my code a bit using this:


Code
-------------------

Sub DropDown1_Change()
'
' DropDown1_Change Macro
' Macro recorded 02/11/2005 by 96bst01
If Range("C4").Value = "1" Then
Range("E4").Select
Selection.NumberFormat = "0%"
ElseIf Range("C4").Value = "2" Then
Range("E4").Select
Selection.NumberFormat = "£#,##0.00"
End If

End Sub

-------------------


Now, this code works fine for one row, but can I have this o
multiple rows?

E.g. having a drop down box which is linked to a cell reference, BU
i need the C4 and E4 to change depending on the row and cell link
How can I achieve this in VBA


--
dok11
-----------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058
View this thread: http://www.excelforum.com/showthread.php?threadid=48102

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro VBA, Drop down IF statement


Sub change_test ()

if range("C4").value = "1" then
range("E4").numberformat = "0.00%"
if range("C4").value = "2" then
range("E4").numberformat = "$0.00"
end if
end if

end sub

that should work..

--
dok11
-----------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058
View this thread: http://www.excelforum.com/showthread.php?threadid=48102



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
Conditional Statement using a Drop down box Meeffas Excel Worksheet Functions 5 May 14th 07 12:31 PM
If statement and Drop-Down Daniel Excel Discussion (Misc queries) 2 April 27th 07 03:58 PM
Need to use if statement with drop down lists has this been done KAMKAM Excel Worksheet Functions 2 March 30th 06 04:26 PM
Macro VBA, Drop down IF statement Matt_2K Excel Programming 0 November 2nd 05 09:03 PM
If statement with a drop down list heater Excel Discussion (Misc queries) 1 September 1st 05 10:26 PM


All times are GMT +1. The time now is 07:02 PM.

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

About Us

"It's about Microsoft Excel"