Press enter during Macro

NormChart55

New Member
Joined
Feb 22, 2022
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a macro that I am trying to update to press the enter key but I am having issues with it working. It pulls up the input box and has the cells and columns I am splitting by, but I have to press enter in the input box before it moves on. The 2 bold lines below are where I cannot figure out how to add a keystroke for enter. I have added a line right below to try this but it never seemed to do anything so I removed it. The data below is not the whole macro but only up to the lines I am trying to adjust. I am sure its an easy fix, any thoughts? I appreciate any information.

VBA Code:
Sub Splitdatabycol()
'updateby Extendoffice
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
Dim xTRg As Range
Dim xVRg As Range
Dim xWSTRg As Worksheet
On Error Resume Next
[B]Set xTRg = Application.InputBox("Please select the header rows:", "Kutools for Excel", "$A$1:$H$1", Type:=8)[/B]
If TypeName(xTRg) = "Nothing" Then Exit Sub
[B]Set xVRg = Application.InputBox("Please select the column you want to split data based on:", "Kutools for Excel", "$H:$H", Type:=8)[/B]
If TypeName(xVRg) = "Nothing" Then Exit Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Why are you using input box in the first place? Are you always using the default ranges or you change them all the time?
Try this
VBA Code:
Application.SendKeys ("{Enter}")
 
Upvote 0
Why are you using input box in the first place? Are you always using the default ranges or you change them all the time?
Try this
VBA Code:
Application.SendKeys ("{Enter}")

thank you for your response. That was a macro that I found and was able to work with my files that are being split. I did not necessarily need the input box. The default ranges never change as the file being split is always the same. Would I place the application.sendkeys right after this line "If TypeName(xTRg) = "Nothing" Then Exit Sub" or would it need to be placed in the inputbox section?
 
Upvote 0
thank you for your response. That was a macro that I found and was able to work with my files that are being split. I did not necessarily need the input box. The default ranges never change as the file being split is always the same. Would I place the application.sendkeys right after this line "If TypeName(xTRg) = "Nothing" Then Exit Sub" or would it need to be placed in the inputbox section?
Then remove the input boxes, input boxes are for dynamic ranges and stuff. I'd personally recommend to convert it all to ranges.
Try changing all the input boxes like this
before
VBA Code:
[B]Set xTRg = Application.InputBox("Please select the header rows:", "Kutools for Excel", "$A$1:$H$1", Type:=8)[/B]
after
VBA Code:
[B]Set xTRg = range("A1:H1")[/B]

before
VBA Code:
[B]Set xVRg = Application.InputBox("Please select the column you want to split data based on:", "Kutools for Excel", "$H:$H", Type:=8)[/B]
after
VBA Code:
[B]Set xVRg = range("H:H")[/B]
 
Upvote 0
Solution
Please note that formatting like "Bold" and "Color" text do not work within VBA code tags (which is why you see all those characters at the beginning and end of your code).
They will work with Rich code tags, but not XLS or VBA code tags.

For example, trying to make text red color within VBA code tags:
VBA Code:
[COLOR=rgb(184, 49, 47)]Set xVRg = range("H:H")[/COLOR]

Making it red within Rich code tags:
Rich (BB code):
Set xVRg = range("H:H")

I see both of you have been trying to do that in your posts.
 
Upvote 0
Please note that formatting like "Bold" and "Color" text do not work within VBA code tags (which is why you see all those characters at the beginning and end of your code).
They will work with Rich code tags, but not XLS or VBA code tags.

For example, trying to make text red color within VBA code tags:
VBA Code:
[COLOR=rgb(184, 49, 47)]Set xVRg = range("H:H")[/COLOR]

Making it red within Rich code tags:
Rich (BB code):
Set xVRg = range("H:H")

I see both of you have been trying to do that in your posts.
thank you, I see that now. much appreciated
 
Upvote 0
Then remove the input boxes, input boxes are for dynamic ranges and stuff. I'd personally recommend to convert it all to ranges.
Try changing all the input boxes like this
before
VBA Code:
[B]Set xTRg = Application.InputBox("Please select the header rows:", "Kutools for Excel", "$A$1:$H$1", Type:=8)[/B]
after
VBA Code:
[B]Set xTRg = range("A1:H1")[/B]

before
VBA Code:
[B]Set xVRg = Application.InputBox("Please select the column you want to split data based on:", "Kutools for Excel", "$H:$H", Type:=8)[/B]
after
VBA Code:
[B]Set xVRg = range("H:H")[/B]

thank you for the insight. Adjusting this to what you provided is doing exactly what I wanted. thanks for the quick assist!
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top