Posts by tswood

    Hello,


    I am trying to sort a column in excel from A to Z. There are cells that contain the following:


    - whole numbers only e.g. 24, 6 etc.
    - whole numbers and text string e.g. 24 years etc.
    - decimal numbers e.g. 7.23, 27.46 etc.
    - decimal numbers and text string e.g. 7.23 years etc.


    I am encountering problems whereby excel 'reads' a number like 7.23 as 723. As a result, it is not sorting properly by putting in the appropriate sequence (e.g. 7, 7.23, 7.5, 8 etc.)


    As there is also text in the cells I am unable to simply switch the cell format to 'number'.


    Is there a way to make sure excel recognizes the decimal numbers appropriately?


    Any assistance would be greatly appreciated.


    Thank you

    Re: Code does not 'run' when assigned to a button


    Okay, thank-you. Let me try that again.


    I created code that executes correctly when I select Run from the VBA screen. The code is within a Standard Code Module (see below).



    I then assigned the code to Button (Form Control) which has caused the code to run incorrectly.


    The first issue is to do with the part of the code that finds a match on wsSource and then copies the columns to wsTarget.


    When I select Run in the VBA screen this occurs (which is correct)


    [ATTACH=CONFIG]70346[/ATTACH]


    When I select the Button the following occurs (which is incorrect):


    [ATTACH=CONFIG]70347[/ATTACH]


    The second issue is that when I select the Button I encounter the following error:

    Run-time error '6': Overflow

    When I select Debug I can see that the part of the code that is causing this error is as follows:


    Code
    maxRowIndex = ActiveCell.Row - 11


    Any assistance would be greatly appreciated.


    Thank-you

    I have created code that works perfectly when I select 'run' from the vba screen, however when I assign this code to a button it fails to run in the same way and encounters errors.


    The code I am using is as follows:



    Is there a reason why this may be occurring?


    Thanks

    Re: Insert and delete rows within an IF statement


    Hello,


    Thank you all for your help and patience with this issue.


    This is the code I am now using:



    It is very likely that I am just not understanding the advice you are giving. I thought I'd try explaining myself a little better in case I haven't been clear.


    After the data from wsSource has been copied to wsTarget I am trying to find a way to do the following:


    1. Delete the row as the data is no longer needed in wsSource
    I believe that this code should do this - Range("N" & i).EntireRow.Delete Shift:=xlUp


    2. There are 101 rows in wsSource (column A has a heading and then is numbered 1 to 100). So that there are always 101 rows I want to add a row at the bottom.
    I believe this code should do this - Range("A100").EntireRow.Insert


    How can I incorporate this into the code listed?

    Re: Insert and delete rows within an IF statement


    The issue I am having is that this code works:



    But this code does not:



    I can see where I am going wrong but not how to fix it.

    Re: Insert and delete rows within an IF statement


    Hello,


    Thank you for your response.


    Here is the full code:



    Yes the sheet I want the range to refer to is the active sheet. Where I have put a (.) before 'Cells' is referring to the non-active sheet.

    Hello,


    In the code below, the lines to delete and insert a row are causing the code not to execute.


    Does anyone have any suggestions on how I might go about rectifying this?


    Re: Copy union / range but skip cell when pasting


    Hello,


    No luck with the above code unfortunately. The code seems to run without incurring any errors, however nothing copies over and the row doesn't delete.


    Here is the original code I was working with prior to the changes:


    Code
    For i = 1 To Cells(Rows.Count, "N").End(xlUp).Row
    If Cells(i, 14) = "no" Then
    Range(Cells(i, 2), Cells(i, 10)).Copy
    wsTarget.Range("B" & wsTarget.Cells(Rows.Count, "B").End(xlUp).Row + 1).PasteSpecial (xlPasteValues)
    Range("M" & i).EntireRow.Delete Shift:=xlUp
    Range("A100").EntireRow.Insert
    End If
    Next i


    It seems to be the addition of the new range to copy that is creating the issue from what I can see.



    As for inserting a row at A100, this is the end of the table so it seemed appropriate to insert a row here so that it doesn't mix up the existing data.

    Re: Copy union / range but skip cell when pasting


    Thanks for this jolivanes.


    I had a little trouble understanding the following:


    Code
    .Resize(, 9).Value = Cells(i, 2).Resize(, 9).Value
    .Offset(, 10).Value = Cells(i, 2).Offset(, 13).Value


    Are you possibly able to elaborate as to what is happening here?


    Thanks again for your help

    Re: Copy union / range but skip cell when pasting


    Hi Luke,


    Thanks for the suggestion. It worked a treat!


    I have since, however, encountered another issue that I was hoping you might be able to assist with.


    I am trying to add as part of the IF condition the following:


    Code
    Range("M" & i).EntireRow.Delete Shift:=xlUp
    Range("A100").EntireRow.Insert


    The problem is that as soon as I add this the macro stops working. Can you perhaps see where I have gone wrong?


    Hello,


    I am trying to paste cells 2 - 10 and 15 to a new target 2 - 12. The issue I am having is that I don't actually want to paste anything in cell 11, rather 2 - 10 paste the same, skip 11, then cell 15 pastes in cell 12.


    Is this possible at all? Here is what I am working with.


    Code
    For i = 1 To Cells(Rows.Count, "M").End(xlUp).Row
    If Cells(i, 13) = "no" Then
    Union(Range(Cells(i, 2), Cells(i, 10)), Cells(i, 15)).Copy
    wsTarget.Range("B" & wsTarget.Cells(Rows.Count, "B").End(xlUp).Row + 1).PasteSpecial (xlPasteValues)
    End If
    
    
    
    
    Next i


    Thank-you

    Hi,


    I am trying to find a way to copy cell ranges 2 - 12 and 14 - 17 to another sheet. I can't seem to work out how to copy range 14 - 17 successfully.


    The code below manages to copy range 2 - 12 and cell 14 only.



    Any assistance would be greatly appreciated.


    Thank you

    Hello,


    In the code below, for the section that reads "Range(Cells(i, 1), Cells(i, 8)).Copy" I want to add Cells(i, 13) but can't seem to work out how.



    Any suggestions?


    Thanks

    Re: Find string match in column then paste adjacent cell


    Hello,


    My apologies... I thought that there was a potential work-around.


    I have managed to get the formula working by including the title (source) data on the active sheet (sheet 5) so that there is an intersect.


    The code it very long winded though and I feel that there must be a shorter version. Also, I'm wondering it it is possible to have the code update automatically when changes are made to the 'source sheet' (sheet 1) rather than having to click on the individual cell every time to update. Is this possible?


    I have included my code below for reference.



    Thank you again

    Re: Find string match in column then paste adjacent cell


    also...


    When I try the code below, Run-time error '424' appears 'Object required'



    The issues is arising from this line...


    Code
    Srch = Sheet2.Range("C1").Value

    Re: Find string match in column then paste adjacent cell


    Hi vcoolio & skywriter,


    I think that I am on the same page as you now so to speak.


    So there is no way to use the 'Intersect' function to reference a cell that is on a different sheet. Correct?


    Currently my workbook contains the following:


    Sheet 2
    - Cell C1 ='Sheet 1'!A6


    Sheet 3
    - Cell C1 ='Sheet 1'!A7


    Sheet 4
    - Cell C1 ='Sheet 1'!A8


    and so on...


    Is there any other way I could approach this task of trying to find the relevant match on sheet 1 for each of the other sheets?


    Thank you for your patience with me also.

    Re: Find string match in column then paste adjacent cell


    Hi vcoolio,


    Thank you for your comprehensive instructions.


    I'm having some issues with the following line:


    Code
    If Intersect(Target, Range("Budget 2016-17!A6")) Is Nothing Then Exit Sub


    It keeps producing the error below:


    Run-time error '1004': Method 'Range' of object '_Worksheet' failed


    Can you see where I am going wrong at all?


    Thanks.