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

Vba to copy data from cells and paste into a workbook saved in Sharepoint

$
0
0
I have exhausted all my resources on this question. Every vba i have created or copied always end the same results either doing nothing, not opening the correct file, or opening a read only file that isnt the file it should be trying to paste the information to. Does anyone have any help or experience with this?

Protect/unprotect

$
0
0
Hello all,

So I created this excel file with a few macros. I have a drop down menu and depending on what you select it will run a specific macro...Issue im having is when I protect the sheet I get the error “the cell or chart you’re trying to change is on a protected sheet. To make a change unprotect sheet. You might he requested to enter a password”. So I have tried codes to unprotect sheet with no luck. Maybe im added them in the wrong place. If I run everything with sheets unprotected it works fine...thanks in advance

[SOLVED] VB code to fill up in first blank cell

$
0
0
Hello:

Please refer to attached file.
I need VB code to enter Date as shown in cell J1 in column A after each filled date.
So in this case i will need 3/15/2020 in each of the yellow highlighted cell.
Next time if i run the code the date will go the next blank cell.

Let me know if you have any questions.
Thanks.

Riz
Attached Files

Selecting a different starting cell for each 'round' in a quiz

$
0
0
I've made a thing for work to help improve local knowledge.
It can have up to 7 players (but usually 4-5 is the norm)
When it starts, player 1 goes first, then player 2 and everyone enters their guess afterwards.
On round 2, I would like player 2 to be selected first, with player 3 going 2nd
Round 3, player 3 and so on....

Where it gets too tricky for me is that there are 7 spaces, but if only 4 players, how do I get it to go back to player 1 on round number 5?


More detail:
On the 'Home' tab, the names of the players are entered. TOP1.png
Pressing the 'Lets play' button shuffles the order and puts the names in the multiplayer sheet (cells L5:R5)TOP2.png
Selecting either Road Name or Landmark buttons starts the game, inserts a '1' next to round number (D3) and selects cell (L7) ready for player 1's answer. Once all players have answered, Check results button is pressed and if answers match, scores are awarded.
Pressing Road name or Landmark again increases round number (D3) by 1, and selects (L7) again, but I would like it to select M8 (as the answer box for player 2TOP4.png
I'd like this to continue, but to know that if only 4 players, to select cell L7 again on round 5 as there is no player 5 in that game.

I hope that makes sense. I couldn't find much help on google (my main source of vba solutions)
Spreadsheet is attached

All help is hugely appreciated.
Regards
Mark
Attached Files

userform command button to run code

$
0
0
please see attached sheet, I need the code to find and total matching records in column T based on the selections made on the 2 comboboxes

combobox1 = week no
combobox2 = shift

all help most appreciated
scouse13
Attached Files

Please Help Create PDF and eMail the file !

$
0
0
Hi,

The range is from B2 to A2=50 rows down and A3=32 columns to right
I have the Print area like that, with offset formula
The PDF file name is cell A4 so A4.pdf
I want to email the file to A5, in A5 is abcdef@outlook.com

Thanks

Pivot Table not being created by VBA Code

$
0
0
I have been struggling to create a pivot table using the following piece of VBA code, but I cannot find the error. I assigned a watch window to PT2, and I noticed after I set PT2 equal to the PivotCache, PTCache2, PT2 still appears with a value of nothing. The With Block does not work because VBA thinks PT2 is an empty object. I am pulling data from a table, GroupDetects, on another sheet, Detects. I am using Excel 2016.

Code:

Sub GroupDetectsPivot()
    Dim PTCache2 As PivotCache
    Dim PT2 As PivotTable 'GroupDetectsPivot PivotTable
   
'Create the cache for the ChemicalDetectsPivot Pivot Table
        Set PTCache2 = ActiveWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:="GroupDetects")  'GroupDetects table on the Detects sheet

    Sheets("DetectsPivot").Activate
    Set PT2 = ActiveSheet.PivotTables.Add( _
        PivotCache:=PTCache2, _
        TableDestination:=Range("F1"), _
        TableName:="GroupDetectsPivot") 'Name the pivot table
       
'Set up GroupDetectsPivot to count detects by group
    With PT2
    .ColumnGrand = False 'Removes grand total row
    .RowGrand = False 'Removes grand total column
    .NullString = "0" 'Shows blank values as 0s
   
    'Add Detects page filter
        With .PivotFields("Detects")
                .Orientation = xlPageField
                .Position = 1
                .PivotItems("ND").Visible = False 'Hide ND findings
                .EnableMultiplePageItems = True 'Allow multiple selections
        End With
    'Add Group field
        With .PivotFields("Group")
            .Orientation = xlRowField
            .Caption = "Group"
            .ShowAllItems = True
        End With
       
      'Add Detects field and rename as "Count of Detects"
        With .PivotFields("Detects")
            .Orientation = xlDataField
            .Caption = "Count of Detects"
        End With
       
        With .PivotFields("Group")
                .AutoSort xlDescending, "Count of Detects"
                .PivotItems("SUM (PFOS + PFOA)").Visible = False 'Hide the sum of PFOS+ PFOA from the pivot table
        End With
       
        'Add the quarter data as a column
        With .PivotFields("Quarter")
            .Orientation = xlColumnField
            .Caption = "Quarters"
        End With
       
    End With
 
End Sub

PT2 Watch Window.png
Attached Files

How to run Macro from another sheet

$
0
0
I have a macro in Sheet3 (Connections), Which is updating pivot table in protected sheet.
I want to run this macro from Sheet4 (Home) and hide Sheet3(connections).

[Code]Sub Refresh()

Application.EnableEvents = False
With ActiveSheet
.Name = "Connections"
.Unprotect Password:="Test"
.PivotTables(1).RefreshTable
.Protect Password:="Test", _
AllowUsingPivotTables:=True
Application.EnableEvents = True
End With

End Sub

delete entire row selecting from listbox starting at specific row

$
0
0
i have a listbox that shows a worksheet data with 9 columns staring from row 16

i need help to modify a code i have ,that supposed deleted selected row from worksheet ,

but it should start counting from row 16 where data starts , but it starts deleting row 5 or row 6




Code:


Private Sub CommandButton2_Click()
 
Rows(ListBox2.ListIndex + 1).EntireRow.Delete
Lastrow = Cells(Rows.Count, "A1").End(xlUp).Row + 1
Data = Range("A16" & Lastrow)
ListBox2.List = Data
End Sub

thank you

Type Mismatch Error

$
0
0
Hello All,

I am getting a Run Time Error '13': Type Mismatch Error with the below code. I am sure I am missing something obvious but I am hoping someone can help me out. I am trying to delete rows based on whether a cell in column A equals a certain word or blank cell. If anyone has any better ideas than what I have, I am more than happy to hear you out.

Thank you

The error is coming from the line that starts with my If statement.

Code:

Dim LR As Long

Application.ScreenUpdating = False

    For LR = ImportSheet.Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
        If ImportSheet.Range("A4:A" & LR).Value = "" Or ImportSheet.Range("A4:A" & LR).Value = "SourceName" Or ImportSheet.Range("A4:A" & LR).Value = "Main list" Then
        Rows(LR).EntireRow.Delete
        End If
       
        Next LR
       
Application.ScreenUpdating = True

[SOLVED] Task the predetermined number N is the degree of the number a

$
0
0
Hi all,
I have a problem with solving this problem since the main idea is to solve it without any branches and loops. I can’t solve it. I will be very grateful for any help.
I will repeat the task again completely: The predetermined number N is the degree of the number a (the exponent may be in the range from 0 to 4).

GIF Animation in Excel for Mac

$
0
0
Hello, my desire is to receive assistance with inserting a GIF animation in a worksheet in Excel for Mac. With the help of this forum, I have successfully accomplished this task in Excel for Windows, now I just need to figure out how to have success in Excel for Mac.

vba color date based on multiple condition

$
0
0
hello
i data colored cells contains dates based on multiple condition my code not completely work so i need help
in column e it works but column f not exactly i specfy when cloumn f= column e+69days not all cells what contains this condition colored by yellow and not colored currewnt month by red as what is existed in my code
HTML Code:

Sub datr()
Dim lr, i As Integer
lr = [d1000].End(xlUp).Row
 For i = 2 To lr
 If Cells(i, 5) < Cells(i, 4) Then
 Cells(i, 5).Interior.Color = vbRed
 If Cells(i, 6) = Cells(i, 4) + 69 Then
 Cells(i, 6).Interior.Color = vbYellow
 If Month(CDate(Cells(i, 6))) = Month(Date) Then
 Cells(i, 6).Interior.Color = vbRed
 End If
 End If
 End If
 Next i
End Sub

Attached Files

List box after update coe

$
0
0
Hi
I'd like to populate a cell from the contents of a list box containing CompanyName once a selection is made. The list box is in Sheet1, the list is generated from CompanyName data in a column in Sheet2. In Sheet3 there is a column containing CompanyName data along with a DiscountRate and various other fields.
When the user selects from the list in Sheet1 I'd like a row next to CompanyName to display the DiscountRate from Sheet3 where the CompanyName in Sheet3 matches the selection made. I think it's some kind of vba after update code but not sure how to implement, any help appreciated, thanks

[SOLVED] VBA To Delete Rows Based On Cell Value

$
0
0
Hi All,

I am trying to delete rows based on cell values in column A. I have attached a sample worksheet as an example of what I am trying to accomplish with the macro embedded. It also has a button on the "OverView" sheet that will run the code on "Sheet1". My code is below.

Here is what I am trying to accomplish:

If there is a cell in column A that is blank, or equals "SourceName" or "Main List" Then I want that whole row to be deleted. Right now my code will compile and run, but it doesn't do anything (doesn't delete any rows despite their being all three cases of conditions above in my test file.

I'm hoping I am close, but I'm also hoping one of you experts can help me out.

Thank you in advance.

Code:

Sub DeleteRow()
Dim LR As Long
Dim ImportSheet As Worksheet
Set ImportSheet = Sheets("Sheet1")


    For LR = ImportSheet.Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
        If ImportSheet.Range("A" & LR).Value = "" Or ImportSheet.Range("A" & LR).Value = "SourceName" Or ImportSheet.Range("A" & LR).Value = "Main list" Then
        Rows(LR).EntireRow.Delete
        End If
       
        Next LR
       


End Sub


[SOLVED] Can't break the endless "Calculate"

$
0
0
Hello,

My spreadsheet, suddenly runs in an endless "Calculate" mode.
The workbook has many macros and I don't know which one is causing this.
I am trying to break it with Ctrl + break, but it won't break.

1. How can I break the loop ?
2. What is procedure to track down the code which causes this?

Could you please advise?
Thanks

Copy and Paste with Ignoring Copying Comments

$
0
0
Hello,

how can i copy and paste (Texts, Formats, Shapes) from a range to another range with ignoring copying comments

Code:

With wksPasteTo

        For Each rngArea In rngPasteToRange.Areas:
         
            wksCopyFrom.Range(rngArea.Address).Copy .Range(rngArea.Address)  '---Copy and Paste Without Comments
       
        Next rngArea

End with

Thank you very much.

Auto fill first column if matched partially the second column.

Update data and copy new data

$
0
0
Hi All

I have two sheets - sheet "Print" contains last week's data. Sheet "Projects" contains this week's data.

Based upon the Project name in Column A I need to do the following:

- Delete rows in "Print" that do not appear in "Projects"
- Add new row in "Print" for rows that only appear in "Projects" (Column A-G) (Column H-J blank)
- Overwrite values in "Print" Column C-Gs for rows that appear in both sheets (but retain Next Step, Owner, Date as stated)
- Msgbox for how many new rows added with empty Next Steps cell.

Many thanks for any help.

Cheers!
Attached Files

Run Same User Form Again, Paste Values in Next Blank Row

$
0
0
Hi,

I have a userform in which when I click "save", the values I selected from the userform would paste in the column I specified.

What I am trying to do is that when I click another button (i.e. called "new service") on the same user form, the same user form would run again and after I select the necessary values on the 2nd user form, it would paste in another cell I specified (the next empty row)


The attachment is an example of what I want it to look like.
To explain the attachment more, if I click the "new service" button on my user form, the user form would pop up and I would enter "work" and the other necessary values. Once I click either "new service" again or "save", the values would paste in this case in "A10" since that is the first empty row (there are values up to C9 from the previous selection).

This is the code I have for pasting the values. "xRow=12" because I want my values to start pasting from row 12, column A from the first user form. Then what I want it to do is when the next user form(s) run, then to paste the values in the next empty row (not in row 12 column A).
Code:

'Paste Selected Listbox Values
Dim xRow As Integer, intItem As Integer
  xRow = 12


 With lstNewService
    For intItem = 0 To .ListCount - 1
        If .Selected(intItem) = True Then
              ThisWorkbook.Worksheets("NewProgramDetails").Cells(xRow, 1).Value = .List(intItem)
                    xRow = xRow + 1
        End If
    Next intItem
End With
 
With lstLocation
    xRow = 12
    For intItem = 0 To .ListCount - 1
        If .Selected(intItem) = True Then
            ThisWorkbook.Worksheets("NewProgramDetails").Cells(xRow, 2).Value = .List(intItem)
                  xRow = xRow + 1
        End If
    Next intItem
End With

With lstCountry
  xRow = 12
  For intItem = 0 To .ListCount - 1
        If .Selected(intItem) = True Then
            ThisWorkbook.Worksheets("NewProgramDetails").Cells(xRow, 3).Value = .List(intItem)
                xRow = xRow + 1
        End If
    Next intItem
End With

If I can't do this, what do you recommend?

This would help a lot.

Thank you!!!
Viewing all 50190 articles
Browse latest View live