Auto Resize Row Height after pasting in Excel - excel

I use MS Excel 2007 to make Bills and Quotation. Often I need to reuse previous quotation.
After I copy a quotation and paste it to new location the row height needs to be readjusted for each row.
is there any solution to this?

I'm not totally sure if this is what you are after. But have you tried something like this?
Private Sub Worksheet_Change(ByVal Target As Range)
' Here you enter a matrix with the cells you want to trigger a Autofit
' If you just want one column to do it, take Range("A1:A200")
Range("A1:C11").EntireRow.AutoFit
End Sub
This code gets the row-size auto-fitted everytime you change the value in the choosen cells.
It's hard to come up with a good solution when you do not give to much information.
Check here :
Excel Worksheet_Change Event not working if my code didn't help you.
Best Regards

Related

How to determine what VBA code is changing the value of an Excel cell

I have a workbook written by someone else and a particular cell is being changed by some code. I cannot figure out the code that is changing the cell value.
I cannot even figure out a strategy to narrow down the code possibilities apart from setting a breakpoint in hundreds of procedures. So I would be happy with strategy ideas.
I am very experienced using VBA in Microsoft Access and a little bit experienced using VBA in Excel.
EDIT
Gotta larf. I cannot even F8 throught the code by starting at the start. What I mean is..
The cell in question changes after I change a value (a year actually) in the worksheet. So I set up a subroutine and breakpoint as below.
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub '<== set breakpoint here
Then I press F8 and no other code is entered by the debugger and yet the cell changes.
The problem may be because there is an awful lot of dynamic formula creation going on in the code. Not sure. Don't know enough about Excel quirks.
EDIT 2
There is a missing formula in the cell in question. Sorry to have wasted everyone's time.
So how can a missing formula change a cell's value. It can't!
The question should have been "How to determine why a cell is NOT changing."
So why didn't I ask that?
I did not notice that other cells in the same column as this cell contain a formula. Because the other cells were changing values correctly and this cell was not, I presumed it was some VBA code not working so I tried to track down the rogue code. I guess not being an experienced Excel person I did not rule out the bleeding obvious and went straight to VBA. Phew!
Add a change event handler on the sheet containing the cell you want to track.
In that Event Handler, add code to break when a change in the tracked cell takes place
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Cells(1, 1)) Is Nothing Then
Stop
End If
End Sub
Chnage Me.Cells(1, 1) to cell of your choosing.
When the code breaks, open the Call Stack, to see where the change came from
Here's a proof of concept. I ran ZX. Call stack shows the Change event at the top. The next function is what changed to cell.

How to prevent Excel from automatically applying word wrap to cell

I noticed that when I'm typing text into a cell that has word wrap off, if the text exceeds the width of the cell, Excel automatically turns word wrap on.
I don't think it happens all the time, and I haven't investigated exactly the conditions, but I found it annoying enough that I wrote a simple macro to solve the problem.
But if there's another approach, I'd be glad to know.
My macro uses the Change event:
Private Sub Worksheet_Change(ByVal Target As Range)
'Replace <...> with an actual condition if desired.
If <target cell is one I want to keep unwrapped> Then
Target.WrapText = False
End If
End Sub
The If statement is optional. I use it to restrict the macro to working in a particular column.
You could also limit it to Targets that are single cell ranges, but it didn't seem necessary in my situation.

VBA code for cell formating linked to another sheet in a workbook

I have a code which looks like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Me.sheets("WAM Data").Range("BY5:HW35").Interior.Color = Me.sheets("WAM
Exception").Range("BO7:HM37").Interior.Color
End Sub
But its giving error in code.
What I want to do is, change the cell formatting (color) of "BY5 to HW35" as "BO7:HM37".
If anyone could help that would be great.
You can delete me. and use only Sheets..., or use ActiveWorkbook.Sheets.. to refer to the activeworkbook, or ThisWorkbook.Sheets... to refer to the workbook the macro is run from, or Workbooks("name").Sheets... to choose whichever workbook you want from the ones you have open.
However, your macro will just run on first click of a mouse, regardless where that happens on your spreadsheet, with no conditions add to it... is that what you want to do with your code?

Best way to link two worksheets in excel- vba

I am looking for the best way to "link" two worksheets together. I have a main worksheet where information and data is added and then I would like to have two basic worksheets that draws columns from main spreadsheet. Whenever changes are made to the main sheet, they will also occur in the other two sheets. I was thinking of trying to activate a macro which automates hitting ctrl or shift and the two tabs like the below
sheets (Array("Main", "Summary")).select
But this failed to work as well. Its too much information for vlookups or anything like that so if anyone knows a way to have changes that occur in one sheet effect multiple other ones it would be much appreciated.
Thanks!!!
You have the worksheet.Change event for that. Something simple like the following:
Private Sub Worksheet_Change(ByVal Target As Range)
ThisWorkbook.Sheets("sheet2").Cells(Target.Row, Target.Column).Value = Target
End Sub
Will copy the value on every cell change from one sheet to another (the code goes in the sheet's private module).

Issue using IF=() function in Excel 2010

I am new to this forum and I am seeking help with creating a function in Excel for data logging purposes. Basically I am trying to use Excel to write a macro simply by pressing "x" in certain cells. For instance, from cells A3-A6 I will have client's names listed there. In addition, I will have dates (of service) listed on the 2nd cell row and on.
9/20 9/21 9/22 9/24
John Doe x
Sara Mitchell x x
Christopher Acha x
Now, I have the macro, I have everything I need in order to set this up. The only problem I am having is to make Excel write the macro for me. I am trying to use the IF=() function, but it limits me to 255 characters, and it tells me to use the concatenate function. All I am trying to do is basically tell Excel that if a certain cell IS true, I would mark it by hitting x; meaning that if a person came on the 24th for service, I would hit x and from there excel would automatically write what I tell it to (in a different sheet or cell). I am stuck here, any help would be greatly appreciated.
You said you have a macro that works, so I'm assuming you want to know how to trigger it automatically when you enter data into a cell.
In your worksheet code use a change event and call your macro from here and pass the range you sent.
Private Sub Worksheet_Change(ByVal Target As Range)
myMacro(Target)
End Sub
You'll probably want to add in additional code to test that the cell changed is within a certain range before calling your macro.

Resources