I have a macro and it perfectly run. however, the result is always shown at the right (latest column).
I tried to add the macro:
select.range("A1")
or
Application.Goto Reference:="R1C1"
and it still is not working.
Is there anyone know how to make the scroll bar at the left (column A) when first open?
I solved this issue.
I add this line "ActiveWindow.LargeScroll ToRight:=-1"
thank you
You're missing Scroll:=True from your code, to scroll the worksheet to the activated range.
Try this:
Application.Goto Reference:=Sheet1.Range("A1"), Scroll:=True
Related
gwbkEach.Worksheets(6).Range(rngDeleteStart, rngDeleteEnd.Offset(-1)).EntireRow.Delete
The above code deletes row 11-54($11:$54). But the shapes which lies beyond Row-54 does not shift upwards. All shapes has the placement property set to xlMoveAndSize.
When I manually delete the rows the shapes re-position themselves
accordingly as expected.
Strangely, when I put a break-point in the above line of code then
everything works fine and the shapes re-position themselves as
expected.
I tried to use DoEvents , Application.Wait around the above line of code, but nothing seems to work. Please help me guys.
The issue got fixed when I added a code to activate the sheet:
gwbkEach.Worksheets(6).Activate ' FIXED THE ISSUE
gwbkEach.Worksheets(6).Range(rngDeleteStart, rngDeleteEnd.Offset(-1)).EntireRow.Delete
NOTE: You have to avoid using Application.ScreenUpdating = False in order for the above solution to work
Something has changed in my VBA that is not allowing me to complete certain routines. I have listed a very simple example below. If anyone has experienced this I would be really appreciate any support in resolving this issue.
Simple example of issue:
When I use the following code it works fine.
Sheets("Sheet1").Select
Range("B3").Select
When I combine them I get a "1004" error
Sheets("Sheet1").Range("B3").Select
I checked the reference/document library and nothing appears to have changed in here. It has to be something simple but I just can't put my finger on it.
If you absolutely must do it in a single line of code then swap the Select for an Application.GoTo which accepts both worksheet and cell range.
application.goto range("Sheet1!B3")
However, it is almost never necessary (and most often counter-productive) to use the Range .Select method to reference a cell or cells to work on. See How to avoid using Select in Excel VBA macros for methods on getting away from relying on select and activate to accomplish your goals.
You already have your answer:
first Select the worksheet
the Select a range on that worksheet
Your code will work if you happen to be on Sheet1 when it is run, but will fail if you are not on Sheet1. In my opinion VBA is kind of dumb with regard to this issue.
i have the following code in an add-in, which is called from the ribbon. It is meant to make all lines visible from the current line to the next visible line. The lines are hidden by an autofilter.
Sub Details4(control As IRibbonControl)
ActiveSheet.Unprotect Password:="xxx"
SendKeys "+{DOWN}+ ", True
ActiveCell.Rows("1:" & Selection.Rows.Count).EntireRow.EntireRow.AutoFit
End Sub
It does mark the lines as i wanted it to do, but the auto-fit does not work. When I double-click the line-height (which should do the same as the autp-fit) alle lines are visible as I wished this do to.
Can anyone see a problem? I know "sendkey" is not the best Thing in programming, but I had no other easy idea how to mark the range up to the next visible line...
Thanks
max
You have an extra .EntireRow call.
Rows("9:13").EntireRow.autofit
Works just fine.
For your sendkey issue, try something like this:
Range(Selection, Selection.End(xlDown)).Select
solved this by changing the code to:
For Each Row In ActiveCell.Rows("1:" & Selection.Rows.Count)
Row.EntireRow.AutoFit
Next
and deleting the line
ActiveCell.Rows("1:" & Selection.Rows.Count).EntireRow.EntireRow.AutoFit
of course...
i need to click a button(FormControl) on an excel sheet and run the macro assigned to it, through VBA code.
I tried what was suggested here
https://stackoverflow.com/questions/130166/clicking-command-button-from-other-workbook
but it didn't work for me.
Is there any other way to do this ??
Fairly easy method for doing this, even if it's not really documented.
CommandButton1.Value = True
Did you actually try? Because you want exaclty what is suggested there.
Application.Run Activesheet.Shapes(1).OnAction
If in a worksheet. I used this in the past and it worked!
Sheet1.CommandButton1_Click
else
Sheets("Sheet Name").CommandButton1_Click
In my case, I needed to add a button, say on Sheet1, to call the code of CommandButton1 on, say, Sheet2. First I had to delete the 'Private' statement that was in front of CommandButton1_Click(). Then I had to call Worksheets("Sheet2").Activate before calling Worksheets("Sheet2").CommandButton1_Click. Then it worked. You can then add Worksheets("Sheet1").Activate to get you back to your original sheet. So:
Private Sub CommandButton1_Click()
Worksheets("Sheet2").Activate
Worksheets("Sheet2").CommandButton1_Click
Worksheets("Sheet1").Activate
End Sub
Pressing Ctrl+End in Excel takes you to the bottom-right-most cell of the worksheet.
If you delete the last rows or columns and save the workbook, this last cell gets updated, as well as the scrollbars.
I remember there was a one line VBA command that you could run that would do the update without having to save the workbook, but I can't remember what the command is - do you have any ideas?
I’ve found something that consistently works to delete those blank rows. You can tell when the “used range” excel is using is too big and is going to add extra blank rows when you use the scroll bar to the right and it goes beyond the last row of actual data when you scroll to the bottom. This will caused extra blank records to be added to the table when it is imported into SQL.
To get rid of them:
Select the entire first row under the last row of data. Hit Ctrl + Shift + Down Arrow to select all the blank rows.
From the Home Tab Select Clear and then Clear All from the Edit menu (picture of a whitish-grey eraser).
Right-click and select Delete.
Goto cell A1 first and then Save.
Press Ctrl + Home and then Ctrl + End (This should take you the correct last cell in the used range (above blank rows).
Click Save again.
Here is the answer:
Sub x()
ActiveSheet.UsedRange
End Sub
Run this and the last cell will be reset.
When none of the above works try this.
Select the unused rows and change the row height.
Now delete the rows and save.
Bingo!
Here's what I did... since none of the above worked (this time that is, which is sad cause this code was running beautifully then all the sudden xlCellTypeLastCell totally failed me.) This will only work if you hardcode the first cell of the region you wanna grab the last cell of... for example I was pasting data tables into a sheet of 12 - 40 columns and 60-90 rows... but since it was a paste, it always started in cell A79...
Worksheets("Data_Import").Activate
Range("A79").CurrentRegion.Select
A = Selection.Rows.Count - 1
B = Selection.Columns.Count - 1
Selection.Offset(A, B).Resize(1, 1).Select
Set DataEnd = Selection
I feel sad to NOT use the cool special cells thing, but alas, if it doesn't work! then I just can't use it. :C
p.s. - you could also throw in a
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).CurrentRegion.Select
This solution works for Excel 2013, but may also work for most recent versions of Excel:
Choose the worksheet where you want to change the last cell, and delete any unused rows and columns
Click on File - Options - Customize Ribbon
Under Main Tabs, check the box next to "Developer", then click OK
On the Developer ribbon that now appears, click Visual Basic
In the upper-left corner, under Microsoft Excel Objects, click on the Sheet Name where you want to force a refresh of the worksheet's last cell
In the menu, click on Run - Refresh, then close the Visual Basic Window
When you hit Ctrl + End, your last cell should now be refreshed.
Check out http://dmcritchie.mvps.org/excel/lastcell.htm#MakeLastCell, found the link from a similar question.
Far from the forgotten one liner, but did solved the problem for me.
Alternatively;
Turn on manual calculation (to preserve references).
create new sheet.
Copy cells and Name of old sheet.
For some reason the code ActiveSheet.UsedRange alone did not work for me on Excel 2016 64-bit to force Excel to reset the last used cell.
This does work for me. Hope this helps.
Rows(25:415).Clear 'deletes contents and formatting
ActiveSheet.UsedRange 'resets last used cell
The solution to change row height to zero and saving worked.
Reopen, set row height to 12 and notice that End Home is no longer at the very bottom right of the worksheet.
THANK YOU. I have been working on this for over two years.
Jim Champaigne
Elkhart, Indiana
I'm not sure why everyone is making it so complicated. Just press Ctrl + PgDn.