Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 50207 articles
Browse latest View live

How to make an application for my excel.

$
0
0
Can someone make an excel application for my excel. thank you so much.

like in youtube video (Create This AMAZING Excel Application that Tracks Purchases, Sales AND Inventory)
thank you
Attached Files

[SOLVED] Change Blank Cells to 0

$
0
0
Hi All,

Been working with VBA on and off for the past few months but still very much at the beginner level. I'm trying to change blanks in each column to show 0 but have been unable to get the macro to work. I have been doing the work in the attached sheet with some samples rows, but ultimately I hope to be able to use the macro in a worksheet with 10,000 rows. I tried to solve this using arrays as its an area that my skills need some work in.

If anyone could help me figure out why this code isn't changing the blanks in columns A2-E8 to 0 I would really appreciate it. I'm hoping that I wasn't that far off and that its a quick fix.

Thank you in advance for your help!

Jim

How do I convert $A1$1 to cell(1,1)?

$
0
0
Hi,

How do I convert

myString = "$A$1"

to Cell(1,1)

Thank you!

add/delete/change

$
0
0
hi guys, I have spreadsheet I am doing for a mate that works for a company, everything was working fine until I started inserting charts, now data can be entered as required but pulling the data up to amend does not work, I have attached the spreadsheet if anybody is able to have a look and help, most appreciated

scouse13

if you can guys the add data button works fine, its the Change/Amend coding for some reason is not working, it did initially?, other code am using I did change the spreadsheet into a table, but I believed this should not alter the codes?

Anyway if one of you could take the time to help me out, much appreciated.

Copy and paste image to Word and rotate it

$
0
0
Hi,

this forum has proven as a great source of help for my project, thank you all very much! I'd like to challenge you with another problem.
I would like to copy a table from Excel, paste it in a Word file and then rotate it 90 degrees. I tried various methods that I found online but they mostly explain how to do it after using .Add and not after pasting from Excel, and the solutions posted there have not worked yet for me.

A minimal example of my code is:
Code:

Sub Export()

Dim wdApp As Object
Dim wdDoc As Object
Dim wdRng As Object
Dim exlRng As Range
Dim evalMatrix As Object

Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
Set exlRng = ActiveSheet.Range(ActiveSheet.Cells(firstRow() - 3, 2), ActiveSheet.Cells(lastRow() + 1, lastColumn))
Set wdRng = wdDoc.Paragraphs(wdDoc.Paragraphs.Count - 2).Range

exlRng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
wdRng.Paste
Set evalMatrix = wdDoc.InlineShapes(1).ConvertToShape
evalMatrix.IncrementRotation -90

End Sub

I also tried variations of this such as wdRng.IncrementRotation -90, wd.Rng.Select Selection.IncrementRotation -90, and others - unsuccessful so far.


I hope you can help me out once more with this one.

PS: Happy Easter to everyone and stay healthy!

Macro applied on large data set - most efficient method?

$
0
0
Hi All,

So every half year I have to do this big task of manipulating a very large data set, around 50,000 rows. Long story short, in my workings I have 15 columns of formula.

When I drag down the formulas, I tend to do it in 5 column chunks. (If I were to do all 15 columns at once, it would freeze my computer). I.e. I have the first row of formula in 5 columns, drag down for 50k lines. Once processed, I copy and special paste all the data (as the formulas take up so much space). I then move onto the next 5 columns and so on. If I don't hard past the data, the spreadsheet becomes unresponsively slow.

I am currently creating a macro to automate this process. however in my Macro, I have coded it so that it does 15 columns of 50k rows in one go, and then hard pastes. My question is, would it be quicker and more efficient if I wrote the Macro to do it in 5 column chunks as I do it previously?

I write this post as it is processing. It is on its 10th minute lol

Thanks

Email Macro paste image in to email and sent to list in designated range Outlook

$
0
0
Need help making this macro work with semailto causing problems is one of the errors.

If there is a better way to this please any help would be amazing.

I have attached file

Code:

Sub GenerateEmail()
Dim sEmailBodyp1 As String
Dim sEmailBodyp2 As String
Dim sEmailSubject As String
Dim sEmailTo As String
Dim OutApp As Object
Dim OutMail As Object
Dim UsedRange As Range

sEmailSubject = ActiveSheet.Range("O2").Value
sEmailBodyp1 = ActiveSheet.Range("B2:K20").Select
    Selection.Copy
sEmailBodyp2 = ActiveSheet.Range("P2").Value

    sEmailTo = ActiveSheet.Range("N2:N15").Value
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
        .To = sEmailTo
        .Subject = sEmailSubject
        .Body = "Good Morning " + vbCrLf + vbCrLf + sEmailBodyp1 + vbCrLf + vbCrLf + sEmailBodyp2
        .Display
    End With

        Set OutMail = Nothing

Next

Set OutApp = Nothing
End Sub

Attached Files

newbook = workbooks.add

$
0
0
Hi all,

I'm new to VBA & I'm new to the forum. I recently inherited a macro that I'm trying to decode.

One of the things I don't understand is:

If you declare a variable and set it as newbook = workbooks.add does it add a workbook every time you use the variable newbook?
Also, if I declare another variable (NewSheet in the example below) which contains the NewBook within its code, will it make a new workbook every time I use it?
If not, why not?

Set NewBook = Workbooks.Add
Set NewSheet = NewBook.Sheets("Sheet1")

With NewBook.Sheets("Sheet1")
.Range("C1").PasteSpecial Paste:=xlPasteColumnWidths
.Range("C1").PasteSpecial Paste:=xlPasteValues
.Range("C1").PasteSpecial Paste:=xlPasteFormats
End With

Thank you,

Savetime

Convert Range to Percentages either by calc or C+P.

$
0
0
In the attached (hypothetical sheet) i have 2 ranges of info, range 1 is numerical against target and range 2 is range one expressed as % of target.
I want to have only 1 range/table. I have part of a macro which copies the second range and pastes it over the first which needs correcting to show proper value
(I will need to have a macro to change it back to numerical).

Is it possible to write a macro to calculate it all on the fly or does it need to copy from a hidden sheet (the data set will be a bit bigger than the example) which is kind of
where I am at. Grateful for any pointers/help.
Attached Files

Convert Data from one worksheet to another

$
0
0
Good Evening,

I tinker a bit with excel and VBA but this one ive been unable to workout (maybe a bit old) LOL.

What I need to do is copy line by line from one worksheet ("Log") to another ("ADIFoutput") but only select the data from each line in ("Log") that is needed.

I have managed the output string which look something like this

In this case I have just select one row range at 947 from selected columns.


This would need to populate down until the last blank line in ("Log") or even from a record number to last record number in column A.

excel info.PNG

I hope the image is displayed as it would not allow me add the code.


Any help would be appreciate been racking my brains over the past few days.


Warm Regards

ExcelNewbie-2020

Copying data from hidden columns

$
0
0
Hello,

I have beginners problem. In my Workbook I have Sheets in which columns E, F, G are hidden and I'm trying to copy data from them to another Sheet. Because I'm going to use loops I need to make it with some variables.

The problem is that if I use "defined range" it works, BUT if I want to define range using variables it's not working (I keep getting RUNTIME ERROR 1004)

Here is my simplified code

Code:

Sub HiddenCopy()

    Dim sh As Integer
    Dim rw As Integer
    sh = 2
    rw = 3
   
    ' Using this just to test variables ...
    Dim x, y, z As String
    x = Worksheets(sh).Cells(rw, 5)
    y = Worksheets(sh).Cells(rw, 6)
    z = Worksheets(sh).Cells(rw, 7)
    Debug.Print x & vbCr & y & vbCr & z

    ' Using "Defined range" it's working ...
    'ThisWorkbook.Sheets(2).Range("E3:G3").Copy
    'ActiveCell.PasteSpecial xlPasteValues

    ' Using variables it's not working ... Run-Time Error 1004
    ThisWorkbook.Sheets(sh).Range(Cells(rw, 5), Cells(rw, 7)).Copy
    ActiveCell.PasteSpecial xlPasteValues

End Sub

So what am I doing wrong? :confused::mad:
Attached Files

Charging data from function msoFileDialogFilePicker

$
0
0
Hello.

I have just starting using vba. I use msoFileDialogFilePicker to charge a .csv file (clicking an activex button) that contains 5,000 rows and 100 columns aprox. I just need to put specific columns in the actual file (another worksheet).

I leave the last part of my code, from this point I'm lost about what I need to do.

I hope you guys can help me, I really need this.

Karen :)
Attached Files

Referring to a cell...

$
0
0
I am trying to connect two subs so they can work together.

In my first sub I have the cursor selecting a cell, let's call it A1 on sheet 'Names'.
(The selected cell will always change).

I would like to have code that will find the first text in 'Sheet1', that matches
the selected text on sheet 'Names', and select that cell on 'Sheet1'.

Seems simple to me, but I don't know how to do it.

Macro to select Files to attach

$
0
0
I have the following macro which generates and email from Excel.

I need the code the code amended to that it allows the user to attach selected files in c:\my documents

Your assistance in this regard is most appreciated



Code:

Sub Email_Reports()
Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window

    ztext = [bodytext]                              'read in text from named cell
Zsubject = [subjectText]
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
   
   
   
 

  Set Sourcewb = ActiveWorkbook

        'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        '.Sheets("Sales1").Copy
    End With


   
   
   

    'Close temporary Window
    TempWindow.Close

    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2016
            Select Case Sourcewb.FileFormat
            Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
            Case 52:
                If .HasVBProject Then
                    FileExtStr = ".xlsm": FileFormatNum = 52
                Else
                    FileExtStr = ".xlsx": FileFormatNum = 51
                End If
            Case 56: FileExtStr = ".xls": FileFormatNum = 56
            Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
            End Select
        End If
    End With

    '    'Change all cells in the worksheets to values if you want
    '    For Each sh In Destwb.Worksheets
    '        sh.Select
    '        With sh.UsedRange
    '            .Cells.Copy
    '            .Cells.PasteSpecial xlPasteValues
    '            .Cells(1).Select
    '        End With
    '        Application.CutCopyMode = False
    '        Destwb.Worksheets(1).Select
    '    Next sh

    'Save the new workbook/Mail it/Delete it



 

   
    TempFilePath = Environ$("temp") & "\"
'  TempFileName = Range("B1") & Format(Now, "dd-mmm-yy h-mm-ss")
  TempFileName = Format(Range("B1"), "mmm-yy ") & Format(Now, "dd-mmm-yy h-mm-ss")

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)



    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail


            .To = Join(Application.Transpose(Range("F1:F4").Value), ";")

            .CC = ""
            .BCC = ""
            .Subject = Zsubject
          .Body = ztext

            '.Body = strBody
            ..Attachments.Add ("C:\my documents")
            'You can add other files also like this
                      .display  'Use .send to send automatically or  .Display to check email before sending
          End With
        On Error GoTo 0
        .Close savechanges:=False
    End With

     
     
    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
   
    Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic


End Sub

[SOLVED] store all item from combobox list to range

$
0
0
how to store all item/list inside combobox to spesific range in worksheet, i use this code but doesn't work at all, i thought i missing something there...

Code:

ws.range("D7:D20").value = combobox2.list

Printform has stopped working..

$
0
0
Hi,

I've been writing vba code in a very amateur capacity for 25 years and have created various applications along the way. Some of these make use of the Printform tool to print out data displayed on a userform.

However, whilst it appears to go through the motions (the little print dialogue box flashes up for a second or so) it has stopped printing them.

There is nothing lurking in the print queue, and when I use the conventional print command to print out part of the spreadsheet, that works fine.

I still use Excel 2003 (on Windows 10) as the newer version drove me insane, and everything else still seems to work fine. Restarting the PC did not solve matters.

- Anyone have any ideas as to what the cause of this might be?

Copying certain cell values based on a true and false selection (yes/no)

$
0
0
Hi there ,

I am using a code below that copies certain cells (in many different sheets) to a main summary sheet "Audit_Summary_Sheet", these are random cells values pasted to range A2:U2 . This all works fine however;

I need to include with this code - (so as a second function), that the same command button copies specific rows with cell value to a sheet "Findings_Summary_Sheet, the trick here however is, if one of the cells value is "No", then it will be copied, if that same cell value is "Yes", then it will not be copied. I have tried to illustrate the cell name with its content below

Copy From: B26 (Date) paste to A, O26(Audit Finding) paste to B, P26(Recommended Action) paste to C, Q26(Responsible) paste to D, R26(Target Date) paste to E, S26(Completed) paste to F, T26(Reason) past to G , U26(Category) paste H

The cells must be copied on the Findings_Summary_Sheet" under the columns indicated "". The cell which contain the True (Yes) or False(No) is cell number S26 - as mentioned, if it is NO then the code should copy that row of cells

Also every time the command button is clicked (to update the two sheet 1 = "Audit_Summary_Sheet" 2= "Findings_Summary_Sheet" it will find the next open row so as to create a sting of historical data

The code I currently have is:


Code:

Function Submit_AuditSheet_Data()

    Dim ws_to As Worksheet
    Dim ws_from As Worksheet
   
    Set ws_from = ActiveSheet
    Set ws_to = Sheets("Audit_Summary_Sheet")
   
    lrow = ws_to.Cells(Rows.Count, "A").End(xlUp).Row
    ' finds that last used row in column "A"
   
    ws_to.Range("A" & lrow + 1).Value = ws_from.Range("C5").Value
    ws_to.Range("B" & lrow + 1).Value = ws_from.Range("J5").Value
    ws_to.Range("C" & lrow + 1).Value = ws_from.Range("J6").Value
    ws_to.Range("D" & lrow + 1).Value = ws_from.Range("C12").Value
    ws_to.Range("E" & lrow + 1).Value = ws_from.Range("J12").Value
    ws_to.Range("F" & lrow + 1).Value = ws_from.Range("J7").Value
    ws_to.Range("G" & lrow + 1).Value = ws_from.Range("C8").Value
    ws_to.Range("H" & lrow + 1).Value = ws_from.Range("E7").Value
    ws_to.Range("I" & lrow + 1).Value = ws_from.Range("D84").Value
    ws_to.Range("J" & lrow + 1).Value = ws_from.Range("D91").Value
    ws_to.Range("K" & lrow + 1).Value = ws_from.Range("E90").Value
    ws_to.Range("L" & lrow + 1).Value = ws_from.Range("K99").Value
    ws_to.Range("M" & lrow + 1).Value = ws_from.Range("K100").Value
    ws_to.Range("N" & lrow + 1).Value = ws_from.Range("K101").Value
    ws_to.Range("O" & lrow + 1).Value = ws_from.Range("K102").Value
    ws_to.Range("P" & lrow + 1).Value = ws_from.Range("K103").Value
    ws_to.Range("Q" & lrow + 1).Value = ws_from.Range("K104").Value
    ws_to.Range("R" & lrow + 1).Value = ws_from.Range("K105").Value
    ws_to.Range("S" & lrow + 1).Value = ws_from.Range("K106").Value
    ws_to.Range("T" & lrow + 1).Value = ws_from.Range("K107").Value
    ws_to.Range("U" & lrow + 1).Value = ws_from.Range("K108").Value
   
   
    Set ws_from = ActiveSheet
    Set ws_to = Sheets("Findings_Summary_Sheet")
   
    lrow = ws_to.Cells(Rows.Count, "A").End(xlUp).Row
    ' finds that last used row in column "A"
   
    ws_to.Range("D" & lrow + 1).Value = ws_from.Range("O26").Value
   
     
End Function


Apologies, I forgot to add the row range of the multiple questions is A25:U69 - all these rows are exactly the same with different questions and remarks

inser row befor total rows

$
0
0
hi
i would simple code to insert row before row of total i have data in my sheet from a2:e10 the e10 is total i would after fill data in row9 and press enter it inserts a new row without affect row of total

Extending a column to current mont with Macro up to current month (horizontal working ok)

$
0
0
Hi Group,
I've literally spent hundreds of hours getting stuck back into Excel programming the last 2 years.

One of the members (Mumps) helped me solve a brain-teaser a year ago with a Macro to automatically fill down the current month. Thanks to his and the forum help, I've managed to modify it for multiple worksheets - it's saved me hours and hours - thankyou so much :)

Here's the original sheet:
Screenshot 2019-02-11 at 19.20.31.png

Here's the code:

Code:

Sub AddDate()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim lastRow As Long, x As Long, dif As Long, ws As Worksheet
    For Each ws In Sheets(Array("EU", "EA", "UK", "BE", "DK", "DE", "EL", "ES", "FR", "IT", "NL", "AT", "PT", "FI", "SE"))
        MsgBox ws.Name
        lastRow = ws.Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        If Year(ws.Range("A" & lastRow).Value) = Year(Date) And Month(ws.Range("A" & lastRow).Value) < Month(Date) Then
            dif = Month(Date) - Month(ws.Range("A" & lastRow).Value)
            For x = 1 To dif
                ws.Cells(lastRow + x, 1).Value = DateAdd("m", x, ws.Cells(lastRow, 1).Value)
            Next x
            ws.Range("B" & lastRow & ":G" & lastRow).AutoFill Destination:=ws.Range("B" & lastRow).Resize(dif + 1, 6)
       
        ElseIf Year(ws.Range("A" & lastRow).Value) < Year(Date) Then
            dif = 12 - Month(ws.Range("A" & lastRow).Value) + Month(Date)
            For x = 1 To dif
                ws.Cells(lastRow + x, 1).Value = DateAdd("m", x, ws.Cells(lastRow, 1).Value)
            Next x
            ws.Range("B" & lastRow & ":G" & lastRow).AutoFill Destination:=ws.Range("B" & lastRow).Resize(dif + 1, 6)
        End If
    Next ws
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub

What I'm trying to do now, is modify it so it fills *across* the page up to the current month, instead of vertically. I'm trying to extend this:

Screenshot 2020-04-12 at 13.08.20.png

So it extends automatically to the current month (as of Writing, April 2020) like this:

Screenshot 2020-04-12 at 13.09.42.png




I've tried, but keep getting Mismatch errors and think I've assassinated the code, and my head is going to go boom soon :eek:

I tried to edit the original code to make it fills horizontally instead of vertically using this edited version of the code:

Code:

Sub extend_all_tab_dates_across_on_my_non_manu_charts()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim lastRow As Long, x As Long, dif As Long, ws As Worksheet
    For Each ws In Sheets(Array("My charts - NON-Manu data"))
'        MsgBox ws.Name


        lastColumn = ws.Range("B:Z").Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
       
        MsgBox lastColumn
       
' ^^ already changed from .Row to .Column

'Can't get this below working, although the code detects the last 'empty' cell so far


        If Year(ws.Range("B" & lastColumn).Value) = Year(Date) And Month(ws.Range("B" & lastColumn).Value) < Month(Date) Then
            dif = Month(Date) - Month(ws.Range("B" & lastColumn).Value)
            For x = 6 To dif
                ws.Cells(lastColumn + x, 2).Value = DateAdd("m", x, ws.Cells(lastColumn, 1).Value)
            Next x
            ws.Range("B" & lastColumn & ":X" & lastColumn).AutoFill Destination:=ws.Range("C" & lastColumn).Resize(dif + 1, 2)

        ElseIf Year(ws.Range("B" & lastColumn).Value) < Year(Date) Then
            dif = 12 - Month(ws.Range("B" & lastColumn).Value) + Month(Date)
            For x = 1 To dif
                ws.Cells(lastColumn + x, 2).Value = DateAdd("m", x, ws.Cells(lastColumn, 1).Value)
            Next x
            ws.Range("B" & lastColumn & ":X" & lastColumn).AutoFill Destination:=ws.Range("B" & lastColumn).Resize(dif + 1,)
        End If
    Next ws
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub

I just wondered if there was anything obvious that I've messed up that anyone can spot as a quick fix?

Any help greatly appreciated,

Best Regards,
Paul

Prevent macros run in a second workbook

$
0
0
Hi all,

as a teacher I give excel workbooks to my students. When the student opens this workbook he/she has macros there, which help them.
These macros start at open file and close file events.
I want to see their results from a master workbook, which opens the student's workbook. But I don't want to allow their macros run.

Ho can I do it?

Thanks in advance your help.

Kaus Borealis
Viewing all 50207 articles
Browse latest View live