Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Please Help with Short Macro

What I am trying to do with this macro is when run, it will prompt the user
for a range of cells in excel, once selected it needs to take the range (i.e.
A1-C1) and then format the cells as follows, A1,";",B1",";",C1 all within one
cell. It would also be nice to limit the range to a max of 225 cells. I can
see ALOT of people using this macro so any help would be appreciated. This
is what I have so far and it may not be very helpful, I am trying to combine
2 separate macros, one that gets a user range and one that formats the cells
into the proper format.

Sub GetUserRange()
Dim UserRange As Range

Output = 565
Prompt = "Select a cell for the output."
Title = "Select a cell"

' Display the Input Box
On Error Resume Next
Set UserRange = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection

' Was the Input Box canceled?
If UserRange Is Nothing Then
MsgBox "Canceled."
Else
UserRange.Range("A1") = Output
End If

(THIS IS WHERE THE MACRO STARTS THAT FORMATS THE CELLS CORRECTLY)
x = 1

Cells(5, 2).Value = ""
While Cells(x, 1).Value < ""
Cells(5, 2).Value = Cells(5, 2) & Replace(Cells(x, 1).Value, " ", "") &
";"
x = x + 1
Cells(4, 3).Value = x - 1
Over_Count = Abs(Cells(4, 5))
Wend
Cells(5, 2).Copy

If x C_Value Then
If Over_Count = 1 Then Vals = " value. " Else Vals = " values. "
UserForm1.Label4 = Over_Count & Vals
UserForm1.Show

Else
UserForm2.Show

End If
Finish:


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Please Help with Short Macro

Maybe you could merge this into your code:

Option Explicit
Sub GetUserRange()
Dim UserRange As Range
Dim Output As Long
Dim myPrompt As String
Dim myTitle As String
Dim myCell As Range
Dim myDelim As String
Dim myString As String

myDelim = ","";"""

Output = 565
myPrompt = "Select a cell for the output."
myTitle = "Select a cell"

' Display the Input Box
Set UserRange = Nothing
On Error Resume Next
Set UserRange = Application.InputBox( _
Prompt:=myPrompt, _
Title:=myTitle, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection
On Error goto 0

' Was the Input Box canceled?
If UserRange Is Nothing Then
MsgBox "Canceled."
Exit Sub '???
End If

If UserRange.Cells.Count 225 Then
MsgBox "Too many cells!"
Exit Sub
End If

UserRange.Range("A1") = Output

myString = ""
For Each myCell In UserRange.Cells
myString = myString & myDelim & myCell.Value
Next myCell

myString = Mid(myString, Len(myDelim) + 1)

MsgBox myString
End Sub

But you're putting 565 in the first cell. You'll never see that first cell's
value.



zulfer7 wrote:

What I am trying to do with this macro is when run, it will prompt the user
for a range of cells in excel, once selected it needs to take the range (i.e.
A1-C1) and then format the cells as follows, A1,";",B1",";",C1 all within one
cell. It would also be nice to limit the range to a max of 225 cells. I can
see ALOT of people using this macro so any help would be appreciated. This
is what I have so far and it may not be very helpful, I am trying to combine
2 separate macros, one that gets a user range and one that formats the cells
into the proper format.

Sub GetUserRange()
Dim UserRange As Range

Output = 565
Prompt = "Select a cell for the output."
Title = "Select a cell"

' Display the Input Box
On Error Resume Next
Set UserRange = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection

' Was the Input Box canceled?
If UserRange Is Nothing Then
MsgBox "Canceled."
Else
UserRange.Range("A1") = Output
End If

(THIS IS WHERE THE MACRO STARTS THAT FORMATS THE CELLS CORRECTLY)
x = 1

Cells(5, 2).Value = ""
While Cells(x, 1).Value < ""
Cells(5, 2).Value = Cells(5, 2) & Replace(Cells(x, 1).Value, " ", "") &
";"
x = x + 1
Cells(4, 3).Value = x - 1
Over_Count = Abs(Cells(4, 5))
Wend
Cells(5, 2).Copy

If x C_Value Then
If Over_Count = 1 Then Vals = " value. " Else Vals = " values. "
UserForm1.Label4 = Over_Count & Vals
UserForm1.Show

Else
UserForm2.Show

End If
Finish:

End Sub


--

Dave Peterson
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
Short Macro Joonas K Excel Discussion (Misc queries) 0 August 7th 08 05:31 PM
ZED - Need a short macro fix [email protected] Excel Discussion (Misc queries) 3 January 19th 07 03:32 PM
Onkey vs Macro Short cut key rgarber50 Excel Discussion (Misc queries) 1 July 10th 05 07:34 PM
Macro short cut key Vispy Excel Programming 1 December 4th 03 06:07 AM
how to enhance this macro (really short) Bob Phillips[_5_] Excel Programming 1 September 9th 03 11:43 PM


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