Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Michael M
 
Posts: n/a
Default InputBox to select cell locations

Hi All
I want to use an InputBox to ask the user for a cell location.
Can someone provide me with some code to do this please.
This is what I have so far.
Basically the last line of the example is where it breaks !!

Any input is appreciated
Michael

Dim x As String, z As Range
Application.ScreenUpdating = False
userEntry = InputBox("Enter Preferred Cell Location")
EndRow = Range("E65536").End(xlUp).Row
Set z = Worksheets("Sheet1").Range("userEntry")
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default InputBox to select cell locations

Option Explicit
sub testme()
dim Rng as range
dim xStr as string
dim nextCell as range

set rng = nothing
on error resume next
set rng = application.inputbox(Prompt:="Click a cell",type:=8)
on error goto 0

if rng is nothing then
'user hit cancel
exit sub '???
end if

with worksheets("someworksheetnamehere")
set nextcell = .cells(.rows.count,"E").end(xlup).offset(1,0)
end with

rng.copy _
destination:=nextcell

end sub

I wasn't sure what you wanted to do, though. I'm not sure I got it right.

Michael M wrote:

Hi All
I want to use an InputBox to ask the user for a cell location.
Can someone provide me with some code to do this please.
This is what I have so far.
Basically the last line of the example is where it breaks !!

Any input is appreciated
Michael

Dim x As String, z As Range
Application.ScreenUpdating = False
userEntry = InputBox("Enter Preferred Cell Location")
EndRow = Range("E65536").End(xlUp).Row
Set z = Worksheets("Sheet1").Range("userEntry")


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Michael M
 
Posts: n/a
Default InputBox to select cell locations

Thanks Dave
Firstly, the code I am using is from a VBA book by Bill Jelens and then
modified by myself. Unfortunately the more I modify, the more I want !!
Basically I want the user to be able to select the cell location they want
the chart to appear in,....anywhere on the sheet !!
As you can see it currently defaults to "G16"

Regards
Michael

Sub PlaceGraph()
Dim x As String, z As Range
Application.ScreenUpdating = False
EndRow = Range("E65536").End(xlUp).Row
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A2:E" & EndRow
& ""), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
x = "G:\Temp\graph.gif"
Set z = Worksheets("Sheet1").Range("G16")
On Error Resume Next
z.Comment.Delete
On Error GoTo 0
Worksheets("Sheet1").ChartObjects(1).Activate
ActiveChart.Export x
With z.AddComment
With .Shape
.Height = 322
.Width = 465
.Fill.UserPicture x
End With
End With
Worksheets("Sheet1").ChartObjects(1).Delete
Application.ScreenUpdating = True
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default InputBox to select cell locations

This works:

Sub GetRange()
Dim myWS As Worksheet
Dim x As String, z As Range, userentry As Range
Dim endrow As Long
Set myWS = ThisWorkbook.Worksheets("sheet1")
Application.ScreenUpdating = False
Set userentry = Application.InputBox(prompt:="Enter Cell location",
Type:=8)
endrow = Range("E" & Rows.Count).End(xlUp).Row

Set z = myWS.Range(userentry.Address)
MsgBox z.Address
Application.ScreenUpdating = True
End Sub

However, I was expecting the inputbox to act a little differently (with the
little icon you can click to let you directly select the cells from the
worksheet.) But it did not do this. I thought that was what type:=8 was
doing. But looking at help, I guess it just ensures that it is a valid cell
reference.
--
Kevin Vaughn


"Michael M" wrote:

Hi All
I want to use an InputBox to ask the user for a cell location.
Can someone provide me with some code to do this please.
This is what I have so far.
Basically the last line of the example is where it breaks !!

Any input is appreciated
Michael

Dim x As String, z As Range
Application.ScreenUpdating = False
userEntry = InputBox("Enter Preferred Cell Location")
EndRow = Range("E65536").End(xlUp).Row
Set z = Worksheets("Sheet1").Range("userEntry")

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Michael M
 
Posts: n/a
Default InputBox to select cell locations

Thank you both for your input
I managed to modify Daves code to meet my needs perfectly.
Sorry, I'm a bit slow with VBA and it took me a while to realise the answer
was there.

Regards
Michael

"Kevin Vaughn" wrote:

This works:

Sub GetRange()
Dim myWS As Worksheet
Dim x As String, z As Range, userentry As Range
Dim endrow As Long
Set myWS = ThisWorkbook.Worksheets("sheet1")
Application.ScreenUpdating = False
Set userentry = Application.InputBox(prompt:="Enter Cell location",
Type:=8)
endrow = Range("E" & Rows.Count).End(xlUp).Row

Set z = myWS.Range(userentry.Address)
MsgBox z.Address
Application.ScreenUpdating = True
End Sub

However, I was expecting the inputbox to act a little differently (with the
little icon you can click to let you directly select the cells from the
worksheet.) But it did not do this. I thought that was what type:=8 was
doing. But looking at help, I guess it just ensures that it is a valid cell
reference.
--
Kevin Vaughn


"Michael M" wrote:

Hi All
I want to use an InputBox to ask the user for a cell location.
Can someone provide me with some code to do this please.
This is what I have so far.
Basically the last line of the example is where it breaks !!

Any input is appreciated
Michael

Dim x As String, z As Range
Application.ScreenUpdating = False
userEntry = InputBox("Enter Preferred Cell Location")
EndRow = Range("E65536").End(xlUp).Row
Set z = Worksheets("Sheet1").Range("userEntry")



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default InputBox to select cell locations

I finally figured out why my inputbox was not working the way I thought it
should. The application.screenupdating = false line prevented me from being
able to select cells from the worksheet.

--
Kevin Vaughn


"Kevin Vaughn" wrote:

This works:

Sub GetRange()
Dim myWS As Worksheet
Dim x As String, z As Range, userentry As Range
Dim endrow As Long
Set myWS = ThisWorkbook.Worksheets("sheet1")
Application.ScreenUpdating = False
Set userentry = Application.InputBox(prompt:="Enter Cell location",
Type:=8)
endrow = Range("E" & Rows.Count).End(xlUp).Row

Set z = myWS.Range(userentry.Address)
MsgBox z.Address
Application.ScreenUpdating = True
End Sub

However, I was expecting the inputbox to act a little differently (with the
little icon you can click to let you directly select the cells from the
worksheet.) But it did not do this. I thought that was what type:=8 was
doing. But looking at help, I guess it just ensures that it is a valid cell
reference.
--
Kevin Vaughn


"Michael M" wrote:

Hi All
I want to use an InputBox to ask the user for a cell location.
Can someone provide me with some code to do this please.
This is what I have so far.
Basically the last line of the example is where it breaks !!

Any input is appreciated
Michael

Dim x As String, z As Range
Application.ScreenUpdating = False
userEntry = InputBox("Enter Preferred Cell Location")
EndRow = Range("E65536").End(xlUp).Row
Set z = Worksheets("Sheet1").Range("userEntry")

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
Select cell, Copy it, Paste it, Return to Previous cell spydor Excel Discussion (Misc queries) 1 December 30th 05 01:29 PM
Select cell containing specific text &return value from another ce plf100 Excel Worksheet Functions 4 November 16th 05 01:57 PM
enhanced conditional formatting Stuart Excel Discussion (Misc queries) 13 November 13th 05 07:20 PM
select a cell and the one next to it Donna S Excel Discussion (Misc queries) 3 November 4th 05 06:53 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM


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

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"