Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default VBA to set value of a cell

I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default VBA to set value of a cell

If rng3.Value = "Shane" Then
rng5.Value = "Private"
Else: rng5.Value = "Public"
End If


"ivory_kitten" wrote:

I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default VBA to set value of a cell

Thanks, I had that but for some reason it was not working! How can I set
this so that it does this on open instead of on change?

"JMB" wrote:

If rng3.Value = "Shane" Then
rng5.Value = "Private"
Else: rng5.Value = "Public"
End If


"ivory_kitten" wrote:

I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA to set value of a cell

Sub ABC()
Dim rng3 as Range, rng5 as Range
set rng3 = Range("B2")
set rng5 = Range("D2")
If rng3 = "Shane" then
rng5.value = "Private"
else
rng5.value = "Public"
End if
End Sub


or if by Named you mean

Sub ABC()
if Range("rng3").Value = "Shane" then
Range("rng5").Value = "Private"
else
range("rng5").Value = "Public"
end if
End Sub


--
Regards,
Tom Ogilvy

"ivory_kitten" wrote in message
...
I want to set cell D2 (named rng5) to a certain text value if cell B2
(named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default VBA to set value of a cell

In the VBE clck on ThisWorkbook and use this line for your Sub:

Private Sub Workbook_Open()
' add your code here'
End Sub
"ivory_kitten" wrote:

Thanks, I had that but for some reason it was not working! How can I set
this so that it does this on open instead of on change?

"JMB" wrote:

If rng3.Value = "Shane" Then
rng5.Value = "Private"
Else: rng5.Value = "Public"
End If


"ivory_kitten" wrote:

I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default VBA to set value of a cell

Ok, i tried that but it's not working, have i done something wrong?

Private Sub Workbook_Open()
Dim rng As Range, rng2 As Range

Set rng = Me.Range("B2")
Set rng2 = Me.Range("D2")

'Private/Toll'
If rng.Value = "Shane Farley" Then
rng2.Value = "Private"
Else: rng2.Value = "Toll"
End If

End Sub

It gets up to Set rng = Me and then it says Compile error: Method or data
member not found

It highlights .Range

Any ideas?

"JLGWhiz" wrote:

In the VBE clck on ThisWorkbook and use this line for your Sub:

Private Sub Workbook_Open()
' add your code here'
End Sub
"ivory_kitten" wrote:

Thanks, I had that but for some reason it was not working! How can I set
this so that it does this on open instead of on change?

"JMB" wrote:

If rng3.Value = "Shane" Then
rng5.Value = "Private"
Else: rng5.Value = "Public"
End If


"ivory_kitten" wrote:

I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default VBA to set value of a cell

Why not just put a formula in D2?

=IF(rng3="Shane","Private","Public")



ivory_kitten wrote:
I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default VBA to set value of a cell

Sorry, I should add that I also have a data validation list so that the user
can change the option if desired, I just need it to show the default value on
opening the workbook, which currently I can't seem to do!

The VBA code I have does not work on the Workbook part!

"Andrew Taylor" wrote:

Why not just put a formula in D2?

=IF(rng3="Shane","Private","Public")



ivory_kitten wrote:
I want to set cell D2 (named rng5) to a certain text value if cell B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5 value to
be set to "Public"

Any help appreciated, thanks!



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA to set value of a cell

Private Sub Workbook_Open()
Dim rng As Range, rng2 As Range

With ThisWorkbook
Set rng = .Worksheets("Sheet1").Range("B2")
Set rng2 = .Worksheets("Sheet1").Range("D2")
End with

'Private/Toll'
If lcase(rng.Value) = "shane farley" Then
rng2.Value = "Private"
Else
rng2.Value = "Toll"
End If

End Sub

--
Regards,
Tom Ogilvy


"ivory_kitten" wrote in message
...
Ok, i tried that but it's not working, have i done something wrong?

Private Sub Workbook_Open()
Dim rng As Range, rng2 As Range

Set rng = Me.Range("B2")
Set rng2 = Me.Range("D2")

'Private/Toll'
If rng.Value = "Shane Farley" Then
rng2.Value = "Private"
Else: rng2.Value = "Toll"
End If

End Sub

It gets up to Set rng = Me and then it says Compile error: Method or data
member not found

It highlights .Range

Any ideas?

"JLGWhiz" wrote:

In the VBE clck on ThisWorkbook and use this line for your Sub:

Private Sub Workbook_Open()
' add your code here'
End Sub
"ivory_kitten" wrote:

Thanks, I had that but for some reason it was not working! How can I
set
this so that it does this on open instead of on change?

"JMB" wrote:

If rng3.Value = "Shane" Then
rng5.Value = "Private"
Else: rng5.Value = "Public"
End If


"ivory_kitten" wrote:

I want to set cell D2 (named rng5) to a certain text value if cell
B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5
value to
be set to "Public"

Any help appreciated, thanks!



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default VBA to set value of a cell

Cheers! I knew i was missing a bit somewhere!

Thanks a lot!

"Tom Ogilvy" wrote:

Private Sub Workbook_Open()
Dim rng As Range, rng2 As Range

With ThisWorkbook
Set rng = .Worksheets("Sheet1").Range("B2")
Set rng2 = .Worksheets("Sheet1").Range("D2")
End with

'Private/Toll'
If lcase(rng.Value) = "shane farley" Then
rng2.Value = "Private"
Else
rng2.Value = "Toll"
End If

End Sub

--
Regards,
Tom Ogilvy


"ivory_kitten" wrote in message
...
Ok, i tried that but it's not working, have i done something wrong?

Private Sub Workbook_Open()
Dim rng As Range, rng2 As Range

Set rng = Me.Range("B2")
Set rng2 = Me.Range("D2")

'Private/Toll'
If rng.Value = "Shane Farley" Then
rng2.Value = "Private"
Else: rng2.Value = "Toll"
End If

End Sub

It gets up to Set rng = Me and then it says Compile error: Method or data
member not found

It highlights .Range

Any ideas?

"JLGWhiz" wrote:

In the VBE clck on ThisWorkbook and use this line for your Sub:

Private Sub Workbook_Open()
' add your code here'
End Sub
"ivory_kitten" wrote:

Thanks, I had that but for some reason it was not working! How can I
set
this so that it does this on open instead of on change?

"JMB" wrote:

If rng3.Value = "Shane" Then
rng5.Value = "Private"
Else: rng5.Value = "Public"
End If


"ivory_kitten" wrote:

I want to set cell D2 (named rng5) to a certain text value if cell
B2 (named
rng3) equals a certain value.

Eg:

If rng3 = Shane then rng5 value to be set to "Private", else rng5
value to
be set to "Public"

Any help appreciated, thanks!




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
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Options Yuvraj Excel Discussion (Misc queries) 0 June 29th 09 11:20 AM
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Yuvraj Excel Discussion (Misc queries) 0 June 26th 09 06:01 PM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 [email protected] Excel Worksheet Functions 1 August 22nd 08 02:04 AM
How to create/run "cell A equals Cell B put Cell C info in Cell D abmb161 Excel Discussion (Misc queries) 5 January 26th 06 06:36 PM
Question: Cell formula or macro to write result of one cell to another cell Frederik Romanov Excel Programming 1 July 8th 03 03:03 PM


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